Spring注入DAO之怪错

 

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>

  <bean name="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 void setSKeywordHibernateDAO(SKeywordHibernateDAO keywordHibernateDAO) {

       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;
 }

 

再次运行,神了没问题了,看来命名不当也会存在问题啊。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值