Java spring ignoreResourceNotFound不工作
我已经配置了一个属性文件,如下所示Java spring ignoreResourceNotFound不工作,java,spring,spring-mvc,properties-file,Java,Spring,Spring Mvc,Properties File,我已经配置了一个属性文件,如下所示 <bean id="applicationHostProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="ignoreResourceNotFound" value="true"></property> <property nam
<bean id="applicationHostProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="ignoreResourceNotFound" value="true"></property>
<property name="locations">
<list>
<value>classpath:applicationHost.properties</value>
</list>
</property>
</bean>
由于我已设置了ignoreResourceNotFound=true,因此如果未找到属性文件,我不希望出现任何错误
但是如果属性文件丢失,我的spring上下文初始化将失败。我做错什么了吗?谢谢你的帮助
错误堆栈跟踪:
创建名为“InstanceConfiguration”的bean时出错
on':通过字段“appsDeployedProperties”表示的未满足的依赖项:Ex
压力解析失败;嵌套的异常是org.springframework.expression.spel
.SpelEvaluationException:EL1008E:(位置0):属性或字段“AppsDeployedProperty”
在类型为“org.springframework.beans.factory.confi”的对象上找不到“关系”
g、 BeanPressionContext”-可能不公开?;嵌套的异常是org.springfram
ework.beans.factory.BeanExpressionException:表达式解析失败;嵌套e
异常为org.springframework.expression.spel.SpelEvaluationException:EL1008E
:(位置0):在对象o上找不到属性或字段“appsDeployedProperties”
f类型“org.springframework.beans.factory.config.BeanExpressionContext”-
大概
不公开?;嵌套的异常是org.springframework.beans.factory.unsatifiedde
pendencyException:创建名为“instanceConfiguration”的bean时出错:Unsati
通过字段“appsDeployedProperties”表示的sfied依赖项:表达式pa
rsing失败;嵌套的异常是org.springframework.expression.spel.SpelEvalua
异常情况:EL1008E:(位置0):属性或字段“appsDeployedProperties”不能
在“org.springframework.beans.factory.config.BeanExpre”类型的对象上找不到
“上下文”-可能不公开?;嵌套的异常是org.springframework.beans
.factory.BeanExpressionException:表达式解析失败;嵌套异常是
org.springframework.expression.spel.SpelEvaluationException:EL1008E:(位置0):P
在类型为“org”的对象上找不到属性或字段“appsDeployedProperties”
.springframework.beans.factory.config.BeanExpressionContext'-可能不是公共的
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanP
ostProcessor$AutowiredFileElement.inject(AutowiredAnnotationBeanPostProcessor.j
ava:569)~[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
在org.springframework.beans.factory.annotation.InjectionMetadata.inject
(InjectionMetadata.java:88)~[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
位于org.springframework.beans.factory.annotation.AutowiredAnnotationBeanP
PostProcessor.PostProcessPropertyValue(AutowiredNotationBeanPostProcessor.java
:349)~[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
您必须将
applicationHost.properties
中的键绑定为String
而不是properties
。例如,如果在applicationHost.properties
中有键appsDeployedProperties
,如下所示:
<bean id="applicationHostProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="ignoreResourceNotFound" value="true"></property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:applicationHost.properties</value>
</list>
</property>
</bean>
applicationHost.properties
appsDeployedProperties=hello
在SpringBean中,必须使用as字符串,如:
@Value("#{appsDeployedProperties}")
private String appsDeployedProperties;
注意:您可以添加值为true
的ignoreunsolvablepholders
键,告诉Spring忽略bean中使用的键,这些键在任何属性文件中都没有提到,如下所示:
<bean id="applicationHostProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="ignoreResourceNotFound" value="true"></property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:applicationHost.properties</value>
</list>
</property>
</bean>
类路径:applicationHost.properties
添加stacktrace请添加错误stack Trace请重新格式化stacktrace,此表单中不可读