0

Is there a special way for doing this? What i got is:

  1. config.properties with param.key=value
  2. web.xml with ContextLoaderListener that reads the configuration
  3. pages-servlet.xml that defines servlet beans.

What I want is to configure one of the beans in pages-servlet.xml with param.key. I'm using <property name="myField" value="${param.key}"/> in the xml but I see that the field is configured with ${param.key} instead of 'value'.

What is the right way to configure the bean?

Ok, I solved it by importing application context file that defines configuration bean into pages-servlet.xml. It works, but seems very wrong.

2
  • 1
    The Spring Framework has fairly detailed documentation, have you read the user guide? springframework.org/documentation
    – cjstehno
    Jul 14, 2011 at 15:23
  • Yes, but couldn't find the answer. If you can point me to the right section instead of giving the general link, I would be grateful.
    – Dima
    Jul 14, 2011 at 15:25

1 Answer 1

3

Property placeholder is what you want.

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:context="http://www.springframework.org/schema/context"
 xsi:schemaLocation="
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-2.5.xsd">
    <context:property-placeholder location="classpath:/config.properties" />
    <bean id="mybean" class="...">
        <property name="xxx" value="${prop.value}" />
    </bean>
</beans>
2
  • yup (+1) and here's the link: static.springsource.org/spring/docs/3.0.x/… Jul 14, 2011 at 15:55
  • This is exactly what I'm using. The problem that it is defined in one of the libraries of the web project and for some reason cannot be seen in the servlet context just like all other beans, despite ContextLoaderListener. It worked after I've imported configuration bean into servlet context file.
    – Dima
    Jul 17, 2011 at 6:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.