stivlo
stivlo

Reputation: 85476

How to use a Spring @Value from properties to set an annotation attribute

I'm trying to set an attribute in an annotation, using Spring @Value, but I get Type mismatch: cannot convert from Value to String. Here is what I tried:

@Table(name = "myTable", catalog = @Value("${database.myCatalog}") )

Is it possible? And if yes, how to do it?

Upvotes: 0

Views: 1142

Answers (1)

ElderMael
ElderMael

Reputation: 7101

I think you are a little bit confused with how Spring uses that annotation.

As far as I know, the only way that annotation can only be set at field or method/constructor parameters.

Also, for Spring to resolve it, the POJO must be a Spring managed bean. That means that it must be defined in the Spring (Web)ApplicationContext implementation to be resolved.

Your question seems like you are annotating a JPA Entity which is not a Spring bean but a Class to be used by the JPA implementation that you are using (e.g. Hibernate).

Upvotes: 2

Related Questions