在 Spring MVC Hibernate 应用程序中,当我尝试使用位于 src/java/resources 下的属性文件时,它会抛出以下错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String com.mcb.controller.UserController.strDefaultPage; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'mcbPage.name'
我正在使用下面的代码来访问我的控制器类中的属性值:
@Value("${mcbPage.name}")
private String strDefaultPage;
我在我的 ApplicationContext.xml 文件中为这个属性文件添加了 bean:
<bean id="mcbProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath*:mcb.properties</value>
<value>file:src/main/resources/mcb.properties</value>
</list>
</property>
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="properties" ref="mcbProperties" />
</bean>
我的属性文件 ( mcb.properties
) 位于 src/main/resources 下。@Autowired
工作正常。但是当尝试使用属性文件时,它会在启动服务器时引发错误。
有人可以帮我解决这个问题吗?