ssh整合遇到action无法实例化问题

胡海潮 2014-02-13 03:12:19
Unable to instantiate Action, com.test.action.TestUserAction, defined for 'testUserAction' in namespace '/'com.test.action.TestUserAction
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:500)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:119)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
root cause

java.lang.ClassNotFoundException: com.test.action.TestUserAction
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
com.opensymphony.xwork2.util.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:157)
com.opensymphony.xwork2.ObjectFactory.getClassInstance(ObjectFactory.java:107)
com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:233)
com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:153)
com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:150)
com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:120)
com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:300)
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:500)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:119)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)


web.xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>DKTest</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- hibernate4 -->
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
</filter>

<!-- struts2 -->
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<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>*.action</url-pattern>
</filter-mapping>

<!-- spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>


applicationContext.xml:配置如下


?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns="http://www.springframework.org/schema/beans"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd"
default-lazy-init="true" default-autowire="byName">

<description>Spring公共配置文件</description>
<!-- 自动扫描的文件目录,用户spring实现IOC要管理的对象 -->
<context:component-scan base-package="com"/>

<!-- 定义受环境影响易变的变量 -->
<!-- 定义数据连接的一些信息,写在 properties配置文件中,这样可以使用${}进行取值,本配置文件中都可以使用-->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value><!-- jdbc.properties是配置文件的名字,需要放在WEB-INF/classes目录下,所有开发时放在src目录下 -->
</list>
</property>
</bean>

<!-- 根据jdbc配置文件生成数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<!-- 使用${}取出配置文件中的相应值 -->
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>

<!-- 数据库连接池的配置 -->
<property name="initialSize" value="1" />
<property name="maxActive" value="1" />
<property name="maxIdle" value="1" />
<property name="maxWait" value="500" />
<property name="defaultAutoCommit" value="false" />
</bean>

<!-- 根据数据源对sessionFactory和持久化对象进行管理 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- 引用数据源,也就是数据库连接 -->
<property name="dataSource" ref="dataSource" />
<!-- 配置自动扫描包下面的类,这些类中使用annocation配置,就看自动转换成hibernate持久化对象 -->
<property name="packagesToScan">
<list>
<!-- 要扫描的包的全路径,可以修改 -->
<value>com.**.model</value>
</list>
</property>

<!-- hibernate的配置信息-这里是从jdbc.properties配置文件中读取的 -->
<property name="hibernateProperties">
<props>
<!-- 指定Hibernate的连接方言 -->
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<!-- 指定是否显示sql语句 -->
<prop key="hibernate.show_sql">
${hibernate.show_sql}
</prop>
<!-- 指定ddl操作类型 -->
<prop key="hibernate.hbm2ddl.auto">
${hibernate.hbm2ddl.auto}
</prop>
</props>
</property>
</bean>

<!-- 管理事务类 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<!-- 引用sessionFactory -->
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- 配置那些方法添加切入通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 指明一下方法去添加配置的transactionManager事务 -->
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="edit*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="batchUpdate" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>

<!-- 配置说明在说明包下面的类中的什么方法上添加aop -->
<aop:config>
<aop:pointcut id="targetMethod" expression="execution(* com.*.service.*Service.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="targetMethod" />
</aop:config>
</beans>



查了好多资料 都无发解决,纠结两天了,请各位大神帮帮忙。
...全文
363 19 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
Huang_ja 2014-06-10
  • 打赏
  • 举报
回复
楼主能不能分享下,和楼主同样的错误,看无数遍了不知道哪错了
胡海潮 2014-02-17
  • 打赏
  • 举报
回复
引用 17 楼 yys79 的回复:
会不会是某个注入项初始化失败造成的? 比如 @Resource private TestUserService testUserService; 这种,把所有注入的东西都去掉,看看是否能进入action
谢谢各位的帮忙,我已找出并解决了错误
胡海潮 2014-02-14
  • 打赏
  • 举报
回复
引用 13 楼 redcenter 的回复:
楼主查看是否是缺少struts2-spring-plugin-2.3.4.jar导致的
我用的是:struts2-spring-plugin-2.1.8.1.jar
陆荃 2014-02-14
  • 打赏
  • 举报
回复
楼主查看是否是缺少struts2-spring-plugin-2.3.4.jar导致的
胡海潮 2014-02-14
  • 打赏
  • 举报
回复
引用 11 楼 yys79 的回复:
[quote=引用 10 楼 u012555539 的回复:] [quote=引用 9 楼 yys79 的回复:] 错误不知道咋回事。但是我看楼主用了好多存在隐患的技术: 1.spring事务管理 2.openSessionInView 这在有点并发量的系统上都不能用,尤其是spring事务管理,没有并发也容易数据源死锁。
推荐下你们现在爱用的比较好的技术[/quote] 爱用,唉,觉得springmvc必struts2好用多了,但是因为以上原因,不得不放弃了。我的建议就是用标准的东西。现在都jee7了,标准技术不少,某些可能没有spring灵活易用,但是标准不会更改,比如servlet,struts,springmvc都基于servlet标准开发的。 我现在用的技术基本上就是jee标准技术: cdi,ejb3。 web方面,strtus2还是好用的,尤其它有cdi plugin,可以与cdi,ejb直接融合 [/quote] 谢谢指教
loveunittesting 2014-02-14
  • 打赏
  • 举报
回复
引用 10 楼 u012555539 的回复:
[quote=引用 9 楼 yys79 的回复:] 错误不知道咋回事。但是我看楼主用了好多存在隐患的技术: 1.spring事务管理 2.openSessionInView 这在有点并发量的系统上都不能用,尤其是spring事务管理,没有并发也容易数据源死锁。
推荐下你们现在爱用的比较好的技术[/quote] 爱用,唉,觉得springmvc必struts2好用多了,但是因为以上原因,不得不放弃了。我的建议就是用标准的东西。现在都jee7了,标准技术不少,某些可能没有spring灵活易用,但是标准不会更改,比如servlet,struts,springmvc都基于servlet标准开发的。 我现在用的技术基本上就是jee标准技术: cdi,ejb3。 web方面,strtus2还是好用的,尤其它有cdi plugin,可以与cdi,ejb直接融合
胡海潮 2014-02-14
  • 打赏
  • 举报
回复
引用 9 楼 yys79 的回复:
错误不知道咋回事。但是我看楼主用了好多存在隐患的技术: 1.spring事务管理 2.openSessionInView 这在有点并发量的系统上都不能用,尤其是spring事务管理,没有并发也容易数据源死锁。
推荐下你们现在爱用的比较好的技术
loveunittesting 2014-02-14
  • 打赏
  • 举报
回复
错误不知道咋回事。但是我看楼主用了好多存在隐患的技术: 1.spring事务管理 2.openSessionInView 这在有点并发量的系统上都不能用,尤其是spring事务管理,没有并发也容易数据源死锁。
胡海潮 2014-02-14
  • 打赏
  • 举报
回复
引用 7 楼 yys79 的回复:
[quote=引用 6 楼 u012555539 的回复:] [quote=引用 5 楼 yys79 的回复:] [quote=引用 4 楼 u012555539 的回复:] 谢谢 用的注解 @Controller public class TestUserAction extends BaseAction{ @Resource private TestUserService testUserService; public void add(){ TestUser testUser = new TestUser(); testUser.setCreateDate(new Date()); testUser.setName("123"); testUserService.add(testUser); } }
@Controller注解,干嘛用的?[/quote] 我用的是ssh MVC模式 @Controller表示控制层 [/quote] @Controller这个是strtus里的注解,还是spring的,我用springmvc倒是用@Controller[/quote]
引用 7 楼 yys79 的回复:
[quote=引用 6 楼 u012555539 的回复:] [quote=引用 5 楼 yys79 的回复:] [quote=引用 4 楼 u012555539 的回复:] 谢谢 用的注解 @Controller public class TestUserAction extends BaseAction{ @Resource private TestUserService testUserService; public void add(){ TestUser testUser = new TestUser(); testUser.setCreateDate(new Date()); testUser.setName("123"); testUserService.add(testUser); } }
@Controller注解,干嘛用的?[/quote] 我用的是ssh MVC模式 @Controller表示控制层 [/quote] @Controller这个是strtus里的注解,还是spring的,我用springmvc倒是用@Controller[/quote] spring的
loveunittesting 2014-02-14
  • 打赏
  • 举报
回复
引用 6 楼 u012555539 的回复:
[quote=引用 5 楼 yys79 的回复:] [quote=引用 4 楼 u012555539 的回复:] 谢谢 用的注解 @Controller public class TestUserAction extends BaseAction{ @Resource private TestUserService testUserService; public void add(){ TestUser testUser = new TestUser(); testUser.setCreateDate(new Date()); testUser.setName("123"); testUserService.add(testUser); } }
@Controller注解,干嘛用的?[/quote] 我用的是ssh MVC模式 @Controller表示控制层 [/quote] @Controller这个是strtus里的注解,还是spring的,我用springmvc倒是用@Controller
胡海潮 2014-02-14
  • 打赏
  • 举报
回复
引用 5 楼 yys79 的回复:
[quote=引用 4 楼 u012555539 的回复:] 谢谢 用的注解 @Controller public class TestUserAction extends BaseAction{ @Resource private TestUserService testUserService; public void add(){ TestUser testUser = new TestUser(); testUser.setCreateDate(new Date()); testUser.setName("123"); testUserService.add(testUser); } }
@Controller注解,干嘛用的?[/quote] 我用的是ssh MVC模式 @Controller表示控制层
loveunittesting 2014-02-14
  • 打赏
  • 举报
回复
引用 4 楼 u012555539 的回复:
谢谢 用的注解 @Controller public class TestUserAction extends BaseAction{ @Resource private TestUserService testUserService; public void add(){ TestUser testUser = new TestUser(); testUser.setCreateDate(new Date()); testUser.setName("123"); testUserService.add(testUser); } }
@Controller注解,干嘛用的?
loveunittesting 2014-02-14
  • 打赏
  • 举报
回复
会不会是某个注入项初始化失败造成的? 比如 @Resource private TestUserService testUserService; 这种,把所有注入的东西都去掉,看看是否能进入action
胡海潮 2014-02-14
  • 打赏
  • 举报
回复
引用 15 楼 yys79 的回复:
lz这个错误是访问时候发生还是启动时就出现的?
我直接用http://localhost:8080/DKTest2/testUserAction_add.action访问报的错
loveunittesting 2014-02-14
  • 打赏
  • 举报
回复
lz这个错误是访问时候发生还是启动时就出现的?
胡海潮 2014-02-13
  • 打赏
  • 举报
回复
谢谢 用的注解 @Controller public class TestUserAction extends BaseAction{ @Resource private TestUserService testUserService; public void add(){ TestUser testUser = new TestUser(); testUser.setCreateDate(new Date()); testUser.setName("123"); testUserService.add(testUser); } }
MK_Code 2014-02-13
  • 打赏
  • 举报
回复
把你的action类贴出来吧,你用了注解?是不是没有添加注解啊
胡海潮 2014-02-13
  • 打赏
  • 举报
回复
谢谢 1.class路径没有错 <struts> <package name="testUser" namespace="/" extends="struts-default"> <action name="testUserAction_*" class="com.test.action.TestUserAction" method="{1}"></action> </package> </struts> 2.我直接用http://localhost:8080/DKTest2/testUserAction_add.action访问报的错 DKTest2为项目名 add为action中的方法
song_wl 2014-02-13
  • 打赏
  • 举报
回复
1.检查struts.xml中class路径是否错误 2.检查页面中调用action的地方是否有拼写错误。

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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