Announcement Announcement Module
Collapse
No announcement yet.
Inject property value in Controller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inject property value in Controller

    Hi,
    I am developing a simple web application using spring mvc. I am struggling to inject a property from a properties file to a field in Controller class. The changes I have done are:
    in root-context.xml:
    Code:
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>classpath*:/config/env/env.properties</value>
                </list>
            </property> 
            <property name="ignoreUnresolvablePlaceholders" value="true"/>
        </bean>
    in servlet-context.xml:
    Code:
    <context:component-scan base-package="...file.web"/>
    I am able to get the basic flow working from jsp to controller and back. But If I try to inject some property in the controller, it fails:
    Code:
    @Value("#{propertyConfigurer.outputFilePath}")
        private String outputFilePath;
    or
    Code:
    @Value("#{propertyConfigurer['outputFilePath']}")
        private String outputFilePath;
    Kindly help me inject some property value using annotation

  • #2
    Please use the search as this question has been answered before.

    In short you are using the wrong classes the PropertyPlaceHolderConfigurer isn't to be used for property sources, you will need a simple Properties object for that. Use the util namespace to load the properties.

    Comment

    Working...
    X