maks
maks

Reputation: 6006

Using @Value annotation

I have 2 property files a.properties and b.properties I've added the to application context as:

<context:property-placeholder location="classpath:a.properties" />
<context:property-placeholder location="classpath:b.properties"/>

First file with properties contains db connection details(this works well) Second - contains properties that are used by some specific bean. In that bean I use these properties via @Value annotation

@Value("#{qw.er}")
private String someA;    
@Value("#{as.df}")
private String someB;

However I get exception during startup:

 org.springframework.expression.spel.SpelEvaluationException: 
EL1008E:(pos 0): Field or property 'qw' cannot be found on object of type 
'org.springframework.beans.factory.config.BeanExpressionContext'

What I'm doing wrong?

Is it possible yo use 2 context:property-placeholder in one file?

PS: Properties qw.er and as.df exist only in file b.properties

Upvotes: 5

Views: 19214

Answers (1)

GokcenG
GokcenG

Reputation: 2811

It is explained here

After defining your properties you should use

@Value("${qw.er}")
private String someA;

Notice $ sign.

Upvotes: 9

Related Questions