从属性文件中读取配置并将其替换为匹配的键,其中beans.xml中的值不起作用

时间:2017-05-02 10:02:53

标签: java xml spring-boot

我是Spring环境的新手,试图从资源目录下的application.properties文件中读取配置,并将匹配的密钥名称替换为beans.xml文件中的值。但它没有用,这是配置细节

application.properties

queue.name=Tasks
broker.value=tcp://192.168.1.3:61616

的beans.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-4.2.xsd
        http://camel.apache.org/schema/spring
        http://camel.apache.org/schema/spring/camel-spring.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.2.xsd"
>

    <context:property-placeholder location="classpath:application.properties" />

    <bean id="jmsConnectionFactory"
        class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="${broker.value}" />
    </bean>
    ......
</beans>

异常

  

引起:   org.springframework.beans.factory.BeanDefinitionStoreException:   名称为&#39; jmsConnectionFactory&#39;的bean定义无效定义于   class path resource [beans.xml]:无法解析占位符   &#39; broker.value&#39;价值&#34; $ {broker.value}&#34 ;;嵌套异常是   java.lang.IllegalArgumentException:无法解析占位符   &#39; broker.value&#39;价值&#34; $ {broker.value}&#34;

修改

从应用程序文件

加载bean.xml文件
 @Bean
    public CamelContext camelContext(ApplicationContext applicationContext) throws Exception {
        ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"beans.xml"});
        return new SpringCamelContext(context);
    }

0 个答案:

没有答案