5

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

5
  • Check out this. You can use @Value("#{myProperties['github.oauth.clientId']}") Commented Jul 17, 2013 at 12:37
  • actually, haven't understood what is myProperties in @Value("#{myProperties['github.oauth.clientId']}") Commented Jul 17, 2013 at 12:56
  • Sorry I've misunderstood your question. You can use <util:properties id="config" location="classpath:b.properties" /> and then @Value("#{config['as.df']}") will be helpful. I will look for usage of <context:property-placeholder also. By the way, the error says Spring is looking for beans named qw/as and fields in them named er/df. Commented Jul 17, 2013 at 13:02
  • am I right? when using property-placeholder one should use ${} as placeholders, but not #{} Commented Jul 17, 2013 at 13:09
  • Yes it seems you are right. I've added an answer with a blog that explains mechanism. Commented Jul 17, 2013 at 13:11

1 Answer 1

9

It is explained here

After defining your properties you should use

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

Notice $ sign.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.