How do I configure a controller bean?

how to configure properties for mvc spring bean controller?

  • Is there a special way for doing this? What i got is: config.properties with param.key=value web.xml with ContextLoaderListener that reads the configuration 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.

  • Answer:

    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>

Dima at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.