E
E
EgorSvinarev2021-10-19 22:45:04
Spring
EgorSvinarev, 2021-10-19 22:45:04

Is it possible to inject a string into an annotation value?

Hello. I need to put a value from the config into the annotation. I want to do it through @Value.
It should look something like this:

@EnableSentry(dsn = @Value(value = "${sentry.sdn}"))
But I am getting an error
Type mismatch: cannot convert from Value to String

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2021-10-20
@EgorSvinarev

on the part of the error
Type mismatch: cannot convert from Value to String
it's just that
dsn
the attribute wants string
replace

@EnableSentry(dsn = @Value(value = "${sentry.sdn}"))

on the
@EnableSentry(dsn ="${sentry.sdn}")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question