spring配置:
<bean name="searchKeywordDAO" class="com.miracle.dm.sdmgr.searchkeyword.dao.impl.SearchKeywordDAOImpl">
<property name="sqlMapClient" ref="sqlMapClient" />
</bean>
<bean name="searchWordManager" class="com.miracle.dm.sdmgr.searchkeyword.service.impl.SWordManagerImpl">
<property name="searchKeywordDAO" ref="searchKeywordDAO"/>
<property name="sKeywordHibernateDAO" ref="sKeywordHibernateDAO"/>
</bean>sKeywordHibernateDAO" class="com.miracle.dm.sdmgr.searchkeyword.dao.impl.SKeywordHibernateDAOImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
SWordManagerImpl.java文件注入代码:
SKeywordHibernateDAO sKeywordHibernateDAO;
public SKeywordHibernateDAO getSKeywordHibernateDAO() {
return sKeywordHibernateDAO;
}
public voidkeywordHibernateDAO) {
sKeywordHibernateDAO = keywordHibernateDAO;
}
启动tomcat服务器,控制台报:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'searchWordManager' defined in ServletContext resource [/WEB-INF/config/applicationContext-sdmgr.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'sKeywordHibernateDAO' of bean class [com.miracle.dm.sdmgr.searchkeyword.service.impl.SWordManagerImpl]: Bean property 'sKeywordHibernateDAO' is not writable or has an invalid setter method. Did you mean 'SKeywordHibernateDAO'?
看来前面的“s”导致问题:把代码修改为:
更改后的代码:
spring配置:
<bean name="searchKeywordDAO" class="com.miracle.dm.sdmgr.searchkeyword.dao.impl.SearchKeywordDAOImpl">
<property name="sqlMapClient" ref="sqlMapClient" />
</bean>
<bean name="searchWordManager" class="com.miracle.dm.sdmgr.searchkeyword.service.impl.SWordManagerImpl">
<property name="searchKeywordDAO" ref="searchKeywordDAO"/>
<property name="keywordHibernateDAO" ref="keywordHibernateDAO"/>
</bean>
<bean name="keywordHibernateDAO" class="com.miracle.dm.sdmgr.searchkeyword.dao.impl.SKeywordHibernateDAOImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
SWordManagerImpl.java文件注入代码:
SKeywordHibernateDAO keywordHibernateDAO;
public SKeywordHibernateDAO getKeywordHibernateDAO() {
return keywordHibernateDAO;
} public void setKeywordHibernateDAO(SKeywordHibernateDAO keywordHibernateDAO) {
this.keywordHibernateDAO = keywordHibernateDAO;
}
再次运行,神了没问题了,看来命名不当也会存在问题啊。