在Spring MVC Hibernate應用程序,當我嘗試使用屬性文件,它是在src/JAVA /資源,它拋出以下錯誤:在Spring MVC Hibernate應用程序中使用屬性文件時拋出錯誤?
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'
我使用下面的代碼中訪問屬性值我控制器類:
<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>
和我的財產音響:
@Value("${mcbPage.name}")
private String strDefaultPage;
我在這個屬性文件我applicationContext.xml文件添加豆le(mcb.properties
)位於src/main/resources下。 @Autowired
工作正常。但是當嘗試使用propert文件時,它在啓動服務器時出現錯誤。
有人可以幫我解決這個問題嗎?
你如何註冊屬性文件? –
@JigarJoshi,現在我已經添加上面的ApplicaitonContext.xml文件。請看一下。 – kamal
你是如何建立你的項目?如果你在eclipse中運行,你是否啓用了autobuild?另外,是否將src/main/resources設置爲構建路徑中的源文件夾?它很可能不會將它放到你的classes目錄中。 – Matt