13

First: I'm using Spring 3.0

I have a problem when configuring my controller class. The controller uses a web service which I want to define the endpoint address using a .properties file.

@Controller
public class SupportController {

    @Value("#{url.webservice}") 
    private String wsEndpoint;

    ...

In my application context xml-file, I've defined this:

<context:property-placeholder location="/WEB-INF/*.properties" />

I've been reading the documentation, trying different approaches (like adding prefix systemProperties.),but I keep getting an error message telling me that it doesn't exist.

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


Ok. I've figured it out.

Now, in the controller:

@Value("#{settings['url.webservice']")

Then in the context configuration I have this "helper bean":

<util:properties id="settings" 
location="/WEB-INF/supportweb.properties"></util:properties>
l3dx
  • 2,930
  • 6
  • 33
  • 43
  • Duplicate: http://stackoverflow.com/questions/1741968/using-spring3-value-to-access-propertyplaceholderconfigurer-values – skaffman Jan 13 '10 at 11:08

3 Answers3

12

This should work, too:

@Value("${url.webservice}") 
private String wsEndpoint;
GeertPt
  • 16,398
  • 2
  • 37
  • 61
3

I have this configuration and it works fine:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
       <list>
         <value>classpath:application.properties</value>
      </list>
    </property>
</bean>

and I iniejct the property in this way

@Value("${root.log.level}") 
private String prop;

the field is correctly initialized to "DEBUG" value.

Enrico
  • 121
  • 2
  • 8
2

you should check that the

<context:property-placeholder location="/WEB-INF/*.properties" />

is defined in webmvc-config.xml where you create instances of the @Controllers

ykhrustalev
  • 604
  • 10
  • 18