报错提示:
- Java code
Error creating bean with name 'bookDao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' of bean class [org.dao.imp.BookDaoImp]: Bean property 'sessionFactory' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' of bean class [org.dao.imp.BookDaoImp]: Bean property 'sessionFactory' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
applicationContext.xml
- Java code
<!-- 对dao进行依赖注入 --> <bean id="bookDao" class="org.dao.imp.BookDaoImp"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!--对service进行依赖注入Dao --> <bean id="bookService" class="org.service.imp.BookServiceImp"> <property name="bookDao" ref="bookDao"></property> </bean> <!-- 对action进行注入 --> <bean id="bookAction" class="org.action.BookAction"> <property name="bookService" ref="bookService"></property> </bean>
BookDaoImp.java
- Java code
public class BookDaoImp extends HibernateDaoSupport implements BookDao{ public D101 selectBook2(String d10145) { List list=this.getHibernateTemplate().find("from D101 where d10145=?",d10145); D101 d101=null; if(list.size()>0){ d101=(D101) list.get(0); } return d101; } }
BookServiceImp.java
- Java code
public class BookServiceImp implements BookService{ private BookDao bookDao; public BookDao getBookDao() { return bookDao; } public void setBookDao(BookDao bookDao) { this.bookDao = bookDao; } public D101 selectBook2(String d10145) { return bookDao.selectBook2(d10145); }}
BookAction.java
- Java code
public class BookAction extends ActionSupport{ private D101 d101; private BookService bookService; public D101 getD101() { return d101; } public void setD101(D101 d101) { this.d101 = d101; } public BookService getBookService() { return bookService; } public void setBookService(BookService bookService) { this.bookService = bookService; } public String selectBook(){ D101 b=bookService.selectBook2(d101.getD10145()); if (b!=null) { Map session=ActionContext.getContext().getSession(); session.put("d101", b); } return SUCCESS; }}
哪里的命名不对吗? 检查了也没看出来,唉~·头疼~
------解决方案--------------------
错误指出来了,sessionFactory有问题。
sessionFactory 怎么配置的,粘下代码
------解决方案--------------------