简体   繁体   English

春天的多种特性。 PropertyPlaceholderConfigurer类中的属性

[英]multiple properties in spring. property in PropertyPlaceholderConfigurer class

I'm trying to create spring project. 我正在尝试创建spring项目。 My goal is build project for jar and war in the future. 我的目标是将来为Jar和War建立项目。 I use abc.properties file in the classpath which contains "conf.path.dir" property. 我在包含“ conf.path.dir”属性的类路径中使用abc.properties文件。 War and jar projects use configuration from different locations. War和jar项目使用来自不同位置的配置。 And I'm about to replace abc.properties at build time and use that to configure my PropertyPlaceholderConfigurer bean. 而且我将在构建时替换abc.properties并将其用于配置我的PropertyPlaceholderConfigurer bean。

<bean id="first" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
      autowire-candidate="false">
    <property name="ignoreUnresolvablePlaceholders" value="true"/>
    <property name="locations">
        <list>
            <value>classpath:abc.properties</value>
        </list>
    </property>
</bean>

<bean id="second" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" depends-on="first">
    <property name="ignoreUnresolvablePlaceholders" value="true"/>
    <property name="locations">
        <list>
            <value>classpath:ax/add.properties</value>
            <value>${conf.path.dir}/main.properties</value>
        </list>
    </property>
</bean>

Unfortunately parameter cannot be determined and I got the following error: 不幸的是,无法确定参数,并且出现以下错误:

{2015\04\01 11:11:58} (ERROR) #com.mys.FooService# The service got unexpected error: 
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [${conf.path.dir}/main.properties] cannot be opened because it does not exist
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:87)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:669)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.mys.FooService.start(FooService.java:149)
    at com.mys.FooService$1ServiceInstanceLock.<init>(FooService.java:12)
    at com.mys.FooService.main(FooService.java:137)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.io.FileNotFoundException: class path resource [${conf.path.dir}/main.properties] cannot be opened because it does not exist
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157)
    at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:143)
    at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:98)
    at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:175)
    at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:156)
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:78)
    ... 13 more

Spring version: 3.2.4 How to fix that and resolve "conf.path.dir" from abc.properties? 春季版本:3.2.4如何解决该问题并从abc.properties中解析“ conf.path.dir”?

Try replacing 尝试更换

<value>${conf.path.dir}/main.properties</value>

with

<value>file:///#{conf.path.dir}/main.properties</value>

That should solve your problem. 那应该解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从PropertyPlaceholderConfigurer类Spring中读取属性 - Not able to read properties from PropertyPlaceholderConfigurer class spring 弹簧。 类加载器 - Spring. Class loader Spring Spring PropertyPlaceholderConfigurer可以忽略属性位置路径中的未设置属性吗? - Can Spring PropertyPlaceholderConfigurer ignore unset properties in a property location path? 弹簧。 如何将相同的属性添加到多个bean? - Spring. How to add same property to multiple beans? PropertyPlaceholderConfigurer类中的locations属性 - locations property in PropertyPlaceholderConfigurer class 带有Spring PropertyPlaceholderConfigurer属性标志的IllegalArgumentException - IllegalArgumentException with Spring PropertyPlaceholderConfigurer properties flag 在Spring中使用PropertyPlaceholderConfigurer创建具有不同值的多个类实例 - creating multiple instances of class with diffrent values using PropertyPlaceholderConfigurer in Spring Spring多个PropertyPlaceholderConfigurer文件和数据库 - Spring Multiple PropertyPlaceholderConfigurer files and database 多个Spring PropertyPlaceholderConfigurer同时出现 - Multiple Spring PropertyPlaceholderConfigurer at the same time 创建PropertyPlaceHolderConfigurer的多个实例-Spring - Creating multiple instances of PropertyPlaceHolderConfigurer - Spring
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM