报错提示: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<!-- 对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.javapublic 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.javapublic 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
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;
}
}哪里的命名不对吗? 检查了也没看出来,唉~·头疼~
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<!-- 对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.javapublic 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.javapublic 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
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 配置: <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="datasource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>org/bean/D101.hbm.xml</value></list>
</property>
</bean>
<bean id="datasource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@192.168.0.19:1521:orcl">
</property>
<property name="username" value="zhanhe40"></property>
<property name="password" value="boaozhanhe40"></property>
</bean>
<bean id="bookDao" class="org.dao.imp.BookDaoImp">
<!--这里错了,sessionFactory 是父类,不是属性 下面一行去掉-->
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<value>org/bean/D101.hbm.xml</value></list>
这个xml文件配置的情况
意思是你的dao要么
extends org.springframework.orm.hibernate3.support.HibernateDaoSupport
要么加上这段代码:
private SessionFactory sessionFactory;public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml">
</property>
</bean> <!-- 配置用户信息userInfo的bean -->
<bean id="userDao" class="com.yaxing.daoImpl.UserDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory"></ref>
</property>
</bean>
<bean id="userService" class="com.yaxing.serviceImpl.UserServiceImpl">
<property name="userDao">
<ref bean="userDao"></ref>
</property>
</bean>
<bean id="userAction" class="com.yaxing.action.UserInfoAction"
scope="prototype">
<property name="userService">
<ref bean="userService"></ref>
</property>
</bean>楼主 这是我的代码,基本差不多,没发现明显的错误~
看看这个,估计对你有用
struts 和 spring 整合的包