Why in the below case @value("${someProperty}") is working while @value("#{someProperty}"), is not working

java, spring, spring-el

Solution

`#{ }` is an expression language feature, while `${ }` is a simple property placeholder syntax.

Expression language means that there is a specific syntax, objects, variables and so on.

When you write "#{someproperty}", you actually referring to the object and expression language engine answers you:

Field or property 'someproperty' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'

Here is what will work:

  @Value("#{'${someproperty}'}")

Problem

I have the below spring configuration: ``` <context:property-placeholder location="classpath:commonSql.properties" /> ``` Now in my class, when I use `@value("#{someproperty}")` it did not work. Then, I changed to `@value("${someproperty}")` and it worked. According to answer of this questions `@value("#{someproperty}")` is SpEL syntax, which is far more capable and complex. It can also handle property placeholders, and a lot more besides but in my case why it's not working ? While the simple one is working how both $ and # are use to evaluate the value. The main thing is `@value("#{someproperty}")` is not working while `@value("${someproperty}")` is working.

Original source

Related problems