SSH整合,将struts与spring,hibernate整合时,测试用例正确,web访问出错
网页(http://localhost:8080/Spring_Registration_SSH_PlusStruts/register)访问时报如下错误:Struts Problem Report
Struts has detected an unhandled exception:
Messages:
org.springframework.core.convert.Property.(Ljava/lang/Class;Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;Ljava/lang/String;)V
Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.convert.Property.(Ljava/lang/Class;Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;Ljava/lang/String;)V
Unable to instantiate Action, com.myspring.registration.action.UserAction, defined for 'register' in namespace '/'Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.convert.Property.(Ljava/lang/Class;Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;Ljava/lang/String;)V
File: org/springframework/beans/BeanWrapperImpl.java
Stacktraces
Unable to instantiate Action, com.myspring.registration.action.UserAction, defined for 'register' in namespace '/'Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.convert.Property.(Ljava/lang/Class;Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;Ljava/lang/String;)V
请各位大虾指点下 问题出在什么地方啊? 坐等回复啊啊啊啊啊
com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:319)
com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:400)
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:194)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:501)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584)
java.lang.Thread.run(Thread.java:619)
struts配置内容为:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.ognl.allowStaticMethodAccess" value="true" />
<package name="front" extends="struts-default">
<action name="register" class="com.myspring.registration.action.UserAction">
<result name="success">
/registerSuccess.jsp
</result>
<result name="fail">
/registerFail.jsp
</result>
</action>
</package>
</struts>
UserAction代码为:
private UserManager um;
public UserAction() {
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
um = (UserManager)ctx.getBean("userManager");
}
public UserManager getUm() {
return um;
}
public void setUm(UserManager um) {
this.um = um;
}
public String execute() throws Exception {
User u = new User();
u.setUsername(username);
u.setPassword(password);
if(um.exists(u)) {
return "fail";
}
um.add(u);
return "success";
}
--------------------编程问答-------------------- 请各位高手帮忙看下什么问题啊 --------------------编程问答-------------------- 求解答啊 貌似说是Jar包有问题 --------------------编程问答-------------------- 通过分析问题处在beans初始化时,action里面的写法
public UserAction() {
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
um = (UserManager)ctx.getBean("userManager");
}
问题处在这里,那在struts的action里面如何用呢?
--------------------编程问答-------------------- Spring 和 Hibernate 共用的一些 jar 文件发生了版本冲突.
解决办法:删除 WEB-INF/lib/asm-2.2.3.jar 然后重启 Tomcat. --------------------编程问答-------------------- @Autowired
private UserManager userManager; --------------------编程问答-------------------- 注解注入,你懂的 --------------------编程问答--------------------
删除 WEB-INF/lib/asm-2.2.3.jar 然后重启 Tomcat 后依然报错
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.convert.Property.<init>(Ljava/lang/Class;Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;Ljava/lang/String;)V
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:741)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
我引用的jar包
--------------------编程问答--------------------
加入这个注解后 cat依然报错呢
Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.convert.Property.<init>(Ljava/lang/Class;Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;Ljava/lang/String;)V
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:741)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1041)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:964)
at org.apache.catalina.startup.HostConfig.deployA --------------------编程问答-------------------- 这就不好说了,我的配置给你参考一下,
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- struts -->
<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>
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<!-- dwr -->
<servlet>
<servlet-name>dwrInvoker</servlet-name>
<servlet-class>org.directwebremoting.spring.DwrSpringServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>crossDomainSessionSecurity</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>allowScriptTagRemoting</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dwrInvoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
applicationContext.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:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd
" default-lazy-init="true" default-autowire="byName">
<context:component-scan base-package="com.unite" />
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost/temp?characterEncoding=UTF-8" />
<property name="user" value="root" />
<property name="password" value="123456" />
<property name="autoCommitOnClose" value="true" />
<property name="maxStatements" value="100" />
<property name="checkoutTimeout" value="5000" />
<property name="idleConnectionTestPeriod" value="3000" />
<property name="initialPoolSize" value="3" />
<property name="minPoolSize" value="3" />
<property name="maxPoolSize" value="8" />
<property name="maxIdleTime" value="7200" />
<property name="acquireIncrement" value="5" />
<property name="maxIdleTimeExcessConnections" value="1800" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/config/hibernate</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.jdbc.batch_size=30
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.cache.use_query_cache=false
hibernate.cache.use_second_level_cache=false
hibernate.dialect=org.hibernate.dialect.MySQLDialect
<!-- hibernate.hbm2ddl.auto=update -->
</value>
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- -->
<dwr:configuration />
<dwr:controller id="dwrController" debug="true" />
<dwr:url-mapping />
<dwr:annotation-scan base-package="com.unite" scanRemoteProxy="true" />
</beans>
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="sys.outer" namespace="/outer" extends="struts-default">
<action name="*" method="{1}" class="sys.userAct">
</action>
</package>
</struts>
--------------------编程问答-------------------- dao
package com.unite.dao.impl;
import java.util.List;
import org.springframework.stereotype.Service;
import com.unite.dao.UserDao;
import com.unite.entity.PageModel;
import com.unite.entity.User;
@Service
public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao {
public Boolean login(String userName, String password) {
return validate("select count(*) from User where userName=? and password=?", new Object[]{ userName, password });
}
public PageModel getPage(Integer pageIndex, Integer radix) {
return getPage("from User", null, pageIndex, radix);
}
public Integer updation(User user) {
return other("update User set userName=?,password=? where id=?", new Object[]{ user.getUserName(), user.getPassword(), user.getId() });
}
public List<String> selfion(String word) {
return self("select userName from User where userName like '" + word + "%'");
}
}
package com.unite.dao.impl;
import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
import com.unite.dao.BaseDao;
import com.unite.dao.PageDao;
import com.unite.entity.PageModel;
/**
* @see 访问数据库的基类dao实现类
* @version 1.0
* */
public abstract class BaseDaoImpl<T extends Serializable> extends PageDao implements BaseDao<T> {
@Autowired
private SessionFactory sessionFactory;
private Session session;
// 保存记录
public T add(T entity) {
getSession().save(entity);
return entity;
}
// 修改记录
public T edit(T entity) {
getSession().update(entity);
return entity;
}
// 删除记录
public T del(Serializable id) {
T entity = get(id);
getSession().delete(entity);
return entity;
}
// 根据ID获得记录
@SuppressWarnings("unchecked")
public T get(Serializable id) {
try {
return (T) getSession().get(getThisClass(), id);
} catch (Exception e) {
return null;
}
}
// 获得表中的所有的实体
@SuppressWarnings("unchecked")
public List<T> getBeans() {
String class1 = getThisClass().toString();
String entity = class1.substring(class1.lastIndexOf(".") + 1);
return (List<T>) getList("from " + entity + " order by id", null);
}
// 获得表中的下一个ID的值
public Long getNextId() {
Long result = 0l;
try {
String class1 = getThisClass().toString();
String entity = class1.substring(class1.lastIndexOf(".") + 1);
Object value = getObject("select max(id) from " + entity, null);
if (null != value) {
result = Long.parseLong(value.toString()) + 1;
} else {
result = 1l;
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/**
* @see 从数据库中获得一个实体类的集合或一列值
* @param hql hql语句
* @param args 参数列表(可以为null)
* @return List 不会为null
*/
@SuppressWarnings("unchecked")
public List getList(String hql, Object[] args) {
try {
return getQuery(hql, args).list();
} catch (Exception e) {
e.printStackTrace();
return new ArrayList();
}
}
/**
* @see 从数据库中获得一个实体或一个值
* @param hql hql语句
* @param args 参数列表(可以为null)
* @return Object
*/
@SuppressWarnings("unchecked")
public Object getObject(String hql, Object[] args) {
List list = getList(hql, args);
if (list.size() > 0) {
return list.get(0);
}
return null;
}
/**
* @see 判断真假(数据库是否有这个记录)
* @param hql hql语句必须是select count(*) from ...
* @param args 参数列表(可以为null)
* @return Boolean
*/
public Boolean validate(String hql, Object[] args) {
try {
Object value = getObject(hql, args);
if (null != value && Integer.parseInt(value.toString()) > 0) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
* @see 获得分页
* @param hql hql语句必须是select * from ...或者from ...
* @param args 参数列表(可以为null)
* @param pageIndex 当前页数
* @param radix 分页的基数
* @return PageModel
* */
public PageModel getPage(String hql, Object[] args, int pageIndex, int radix) {
try {
String countHql = "";
if (hql.indexOf("*") != -1) {
countHql = hql.replace("*", "count(*)");
} else {
countHql = "select count(*) " + hql;
}
Integer amount = Integer.parseInt(getObject(countHql, args).toString());
PageModel model = getPageModel(amount, pageIndex, radix, radix);
Query query = getQuery(hql, args);
query.setFirstResult(model.getStart());
query.setMaxResults(radix);
model.setList(query.list());
return model;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* @see 其他操作(增删改返回受影响的行数)
* @param hql hql语句
* @param args 参数列表(可以为null)
* @return Object
*/
public Integer other(String hql, Object[] args) {
try {
return getQuery(hql, args).executeUpdate();
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
/**
* @see 搜索引擎
* @param hql hql语句
* @return List
*/
@SuppressWarnings("unchecked")
public List<String> self(String hql) {
try {
Query query = getQuery(hql, null);
query.setFirstResult(0);
query.setMaxResults(15);
return query.list();
} catch (Exception e) {
e.printStackTrace();
return new ArrayList<String>();
}
}
// 获得session
private Session getSession() {
if (null == session) {
session = SessionFactoryUtils.getSession(sessionFactory, true);
}
return session;
}
// 获得Query
private Query getQuery(String hql, Object[] args) {
Query query = getSession().createQuery(hql);
if (null != args && args.length > 0) {
for (int i = 0; i < args.length; i++) {
query.setParameter(i, args[i]);
}
}
return query;
}
// 获得class
@SuppressWarnings("unchecked")
private Class<T> getThisClass() {
return (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}
}
action
package com.unite.web.action;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.opensymphony.xwork2.ActionSupport;
import com.unite.dao.UserDao;
@Scope("prototype")
@Controller("sys.userAct")
public class UserAct extends ActionSupport {
private static final long serialVersionUID = 1L;
public String login() throws IOException {
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/plain;charset=UTF-8");
PrintWriter out = response.getWriter();
if (userDao.login(userName, password)) {
out.print("登录成功!");
} else {
out.print("登录失败!");
}
out.flush();out.close();
return null;
}
@Autowired
private UserDao userDao;
private String userName;
private String password;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
dwr
package com.unite.web.dwr;
import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;
import org.springframework.beans.factory.annotation.Autowired;
import com.unite.dao.UserDao;
@RemoteProxy(name="user")
public class UserDwr {
@Autowired
private UserDao userDao;
@RemoteMethod
public String getUserName(Long id) {
return userDao.get(id).getUserName();
}
}
因为spring是3.x的版本,所以都用了注解注入,配置文件没有以前那么啰嗦了,
这样配置后,可以运行无异常! --------------------编程问答-------------------- 目前还是报这个错 莫名奇妙啊 明明导入的包包含改文件
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.convert.Property.<init>(Ljava/lang/Class;Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;Ljava/lang/String;)V
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:741)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
Caused by: java.lang.NoSuchMethodError: org.springframework.core.convert.Property.<init>(Ljava/lang/Class;Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;Ljava/lang/String;)V
at org.springframework.beans.BeanWrapperImpl.property(BeanWrapperImpl.java:501)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:496)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:490)
贴出我的配置文件及Action:
web.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- spring -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- struts -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
applicationContext.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:context="http://www.springframework.org/schema/context"
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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="com.myspring.registration" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/spring" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.myspring.registration.model.User
</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<aop:config>
<aop:pointcut expression="execution(public * com.myspring.service.*.*(..))"
id="bService" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="bService" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
</beans>
struts.xml 代码:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.ognl.allowStaticMethodAccess" value="true" />
<package name="user" namespace="/" extends="struts-default">
<action name="register" class="com.myspring.registration.action.UserAction">
<result name="success"> /registerSuccess.jsp </result>
<result name="fail"> /registerFail.jsp </result>
</action>
</package>
</struts>
--------------------编程问答--------------------
UserAction.java文件:
package com.myspring.registration.action;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.myspring.registration.model.User;
import com.myspring.registration.service.UserManager;
import com.opensymphony.xwork2.ActionSupport;
@Scope("prototype")
@Component("user")
public class UserAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private String username;
private String password;
private String password2;
private UserManager um;
public UserManager getUm() {
return um;
}
@Resource(name="userManager")
public void setUm(UserManager um) {
this.um = um;
}
@Override
public String execute() throws Exception {
User u = new User();
u.setUsername(username);
u.setPassword(password);
if(um.exists(u)) {
return "fail";
}
um.add(u);
return "success";
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public String getPassword2() {
return password2;
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public void setPassword2(String password2) {
this.password2 = password2;
}
}
UserManagerImpl.java文件:
package com.myspring.registration.service.impl;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import com.myspring.registration.dao.UserDao;
import com.myspring.registration.dao.impl.UserDaoImpl;
import com.myspring.registration.model.User;
import com.myspring.registration.service.UserManager;
@Component("userManager")
public class UserManagerImpl implements UserManager {
private UserDao userDao;
public UserDao getUserDao() {
return userDao;
}
@Resource(name = "userDao")
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
/* (non-Javadoc)
* @see com.myspring.registration.service.UserManagerImpl#exists(com.myspring.registration.model.User)
*/
public boolean exists(User u) throws Exception {
System.out.println("==="+userDao);
return userDao.checkUserWithName(u.getUsername());
}
/* (non-Javadoc)
* @see com.myspring.registration.service.UserManagerImpl#add(com.myspring.registration.model.User)
*/
public void add(User u) throws Exception {
userDao.save(u);
}
}
UserDaoImpl.java代码:
package com.myspring.registration.dao.impl;
import javax.annotation.Resource;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Component;
import com.myspring.registration.dao.UserDao;
import com.myspring.registration.model.User;
import com.myspring.registration.util.HibernateUtil;
@Component("userDao")
public class UserDaoImpl implements UserDao {
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
@Resource
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public void save(User u) {
Session s = sessionFactory.openSession();
s.beginTransaction();
s.save(u);
s.getTransaction().commit();
}
public boolean checkUserWithName(String username) {
Session s = sessionFactory.openSession();
s.beginTransaction();
long count = (Long)s.createQuery("select count(*) from User u where u.username = ?")
.setParameter(0, username)
.uniqueResult();
s.getTransaction().commit();
if(count > 0) {
return true;
}
return false;
}
}
请帮忙分析下问题出在什么地方啊?貌似是有包冲突引起的。。。求指点。。 --------------------编程问答-------------------- 使用的SSH版本为:struts2.3.4+spring3.2+hibernate4.17 --------------------编程问答-------------------- 你用的版本真新,我的hibernate是4.16,别的跟你的版本一样。我这边没问题,可直接加我好友索取 --------------------编程问答-------------------- 谢谢啊 我的问题已经解决了 Tomcat版本问题
补充:Java , Java EE