有没有一种特殊的方法可以做到这一点?
我得到的是:


带有param.key = value的config.properties
带有ContextLoaderListener的web.xml读取配置
pages-servlet.xml,用于定义servlet bean。


我想要的是使用param.key在pages-servlet.xml中配置一个bean。
我在xml中使用<property name="myField" value="${param.key}"/>,但我看到该字段是用${param.key}而不是'value'配置的。

什么是配置Bean的正确方法?

好的,我通过将定义配置bean的应用程序上下文文件导入pages-servlet.xml中来解决它。
它可以工作,但是看起来很不对。

最佳答案

属性占位符是您想要的。

<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>

09-11 03:36
查看更多