求解,在结成strut2+spring2+hibernate3的时候启动出错了

zhangfengsummer 2008-12-14 06:10:28
在集成这3个框架的时候,遇到了一个问题,网上查了好久也没有解决,寄希望于这里的哥们解答了

是在tomcat启动的时候报的错。

错误信息如下:
错误信息如下:


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'LoginDAO' defined in file [E:\projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Spring2_Struts1_Hibernate3\WEB-INF\classes\config\spring\applicationContext-dao.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor': Cannot resolve reference to bean 'txAdvice' while setting bean property 'advice'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txAdvice': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in file [E:\projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Spring2_Struts1_Hibernate3\WEB-INF\classes\config\spring\applicationContext-common.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' of bean class [org.springframework.jdbc.datasource.DataSourceTransactionManager]: 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.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor': Cannot resolve reference to bean 'txAdvice' while setting bean property 'advice'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txAdvice': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in file [E:\projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Spring2_Struts1_Hibernate3\WEB-INF\classes\config\spring\applicationContext-common.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' of bean class [org.springframework.jdbc.datasource.DataSourceTransactionManager]: 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.factory.BeanCreationException: Error creating bean with name 'txAdvice': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in file [E:\projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Spring2_Struts1_Hibernate3\WEB-INF\classes\config\spring\applicationContext-common.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' of bean class [org.springframework.jdbc.datasource.DataSourceTransactionManager]: 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.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in file [E:\projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Spring2_Struts1_Hibernate3\WEB-INF\classes\config\spring\applicationContext-common.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' of bean class [org.springframework.jdbc.datasource.DataSourceTransactionManager]: 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.springframework.jdbc.datasource.DataSourceTransactionManager]: 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?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:751)

我的setter肯定都有,但是不知道什么问题了,请大家帮我看看是什么地方出了问题。
代码及配置如下:
...全文
244 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangfengsummer 2008-12-14
  • 打赏
  • 举报
回复
wj_18 说的是正解,确实是。

改完后就好了

结贴给分,谢谢大家的帮助。
ahlon 2008-12-14
  • 打赏
  • 举报
回复
'org.springframework.aop.aspectj.AspectJPointcutAdvisor' 对象无法创建
好像是缺少spring-framework-2.5.5-with-dependencies包吧
wj_18 2008-12-14
  • 打赏
  • 举报
回复
看LZ的配置,代码应该都没什么问题,估计也是参考着来的

1,确认包是否都倒全,包括,aspectJ,tx的包

2,建议先把application-*.xml等一系列文件放到WEB-INF目录下再测试一下(虽然你的放到class目录也没什么错)

3,把
 
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>


这段里的事务管理器支持类换成专为hibernate支持的那个试一下,如果没记错,应该是org.springframework.orm.hibernate3.HibernateTransactionManager

zhangfengsummer 2008-12-14
  • 打赏
  • 举报
回复
LoginAction.java


package com.ssh.actions;

import java.util.logging.Logger;

import com.ssh.base.BaseAction;
import com.ssh.service.LoginService;

public class LoginAction extends BaseAction {

/**
*
*/
private static final long serialVersionUID = 7705779920812472933L;

private String userName;

private String password;

private LoginService loginService;

Logger log = Logger.getLogger(this.getClass().getName());

public String Login() {
//log.info("LoginAction.Login()....User:" + userName);

loginService.login(userName, password);
return "success";
}

public void setUserName(String userName) {
this.userName = userName;
}

public void setPassword(String password) {
this.password = password;
}

public String getUserName() {
return userName;
}

public String getPassword() {
return password;
}

public LoginService getLoginService() {
return loginService;
}

public void setLoginService(LoginService loginService) {
this.loginService = loginService;
}

}



LoginServiceImpl.java 是实现了LoginService接口的类


package com.ssh.service.impl;

import java.util.logging.Logger;

import com.ssh.dao.LoginDAO;
import com.ssh.service.LoginService;

public class LoginServiceImpl implements LoginService {

Logger log = Logger.getLogger(this.getClass().getName());

private LoginDAO loginDAO;

public void login(String userName, String password) {

//log.info("LoginServiceImpl.login()....username=" + userName + ",password=" + password);
loginDAO.login(userName, password);
}

public LoginDAO getLoginDAO() {
return loginDAO;
}

public void setLoginDAO(LoginDAO loginDAO) {
this.loginDAO = loginDAO;
}
}



LoginDAO.java


package com.ssh.dao;

import org.apache.log4j.Logger;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ssh.model.User;


public class LoginDAO extends HibernateDaoSupport{

Logger log = Logger.getLogger(this.getClass());


public void login(String userName,String password) {

log.info("LoginDAO.login(String userName,String password)");
log.info("username=" + userName + ",password=" + password);
}

public void insertUser(String userName,String password) {
User user = new User();
user.setPassword(password);
user.setUsername(userName);

this.getHibernateTemplate().save(user);
}
}



好了,其实我觉得也没有什么,就是action里调用了一个service,service里调用了一个dao,dao里注入的sessionFactory, 但是就是说sessionFactory不可注入。
大家帮帮忙吧,谢谢
zhangfengsummer 2008-12-14
  • 打赏
  • 举报
回复
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring2_Struts1_Hibernate3</display-name>

<welcome-file-list>
<welcome-file>example/index.jsp</welcome-file>
</welcome-file-list>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:config/spring/applicationContext-*.xml
</param-value>


</context-param>

<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>
WEB-INF/log4j.properties
</param-value>
</context-param>

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

</web-app>


struts.xml


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.action.extension" value="action,do"></constant>
<constant name="struts.objectFactory" value="spring"/>

<include file="config/struts/example.xml"/>

<!-- Add packages here -->

</struts>


example.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<package name="example" namespace="/login" extends="struts-default">

<action name="login" class="loginaction" method="Login">
<result name="success">/example/login_success.jsp</result>
</action>


<!-- Add actions here -->
</package>
</struts>


applicationContext-common.xml


<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">


<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://127.0.0.1/jbpm"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/ssh/model/mapping/User.hbm.xml</value>
</list>
</property>
</bean>

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut id="allServiceMethod" expression="execution(* com.ssh.service.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allServiceMethod"/>
</aop:config>
</beans>



applicationContext-action.xml


<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">


<bean id="loginaction" class="com.ssh.actions.LoginAction" >
<property name="loginService" ref="LoginService"/>
</bean>
</beans>


applicationContext-service.xml


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">


<bean id="LoginService" class="com.ssh.service.impl.LoginServiceImpl" >
<property name="loginDAO" ref="LoginDAO"/>
</bean>
</beans>


applicationContext-dao.xml


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">


<bean id="LoginDAO" class="com.ssh.dao.LoginDAO" >
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>

下边是java文件
jumpheightway 2008-12-14
  • 打赏
  • 举报
回复
有个jar包有问题
把它去掉

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧