Results 1 to 2 of 2

Thread: Inject property value in Controller

  1. #1
    Join Date
    Apr 2012
    Location
    chennai
    Posts
    17

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •