struts2 + spring 很奇怪的错误,有经验的来看看100分求助。

jiankewuming 2011-12-05 10:30:52
异常信息如下
10:20:56,468 DEBUG DefaultListableBeanFactory:385 - No bean named 'org.apache.struts2.dispatcher.ServletDispatcherResult' found in org.springframework.beans.factory.support.DefaultListableBeanFactory@1eda64e: defining beans [errorMsgSendDao,errMsgSendService,propertyConfigurer,transactionManager,txAdvice,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,dataSource,jdbcTemplate]; root of factory hierarchy
10:20:56,500 DEBUG DefaultListableBeanFactory:198 - Ignoring constructor [public org.apache.struts2.dispatcher.ServletDispatcherResult(java.lang.String)] of bean 'org.apache.struts2.dispatcher.ServletDispatcherResult': org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.apache.struts2.dispatcher.ServletDispatcherResult': Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.String]: : No unique bean of type [java.lang.String] is defined: Unsatisfied dependency of type [class java.lang.String]: expected at least 1 matching bean; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [java.lang.String] is defined: Unsatisfied dependency of type [class java.lang.String]: expected at least 1 matching bean
10:20:56,531 DEBUG DefaultListableBeanFactory:214 - Returning cached instance of singleton bean 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0'
10:20:56,546 DEBUG DefaultListableBeanFactory:214 - Returning cached instance of singleton bean 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0'
10:20:56,562 DEBUG CachedIntrospectionResults:218 - Getting BeanInfo for class [org.apache.struts2.dispatcher.ServletDispatcherResult]
10:20:56,593 DEBUG CachedIntrospectionResults:234 - Caching PropertyDescriptors for class [org.apache.struts2.dispatcher.ServletDispatcherResult]
10:20:56,609 DEBUG CachedIntrospectionResults:243 - Found bean property 'class' of type [java.lang.Class]
10:20:56,625 DEBUG CachedIntrospectionResults:243 - Found bean property 'encode' of type [boolean]
10:20:56,625 DEBUG CachedIntrospectionResults:243 - Found bean property 'lastFinalLocation' of type [java.lang.String]
10:20:56,640 DEBUG CachedIntrospectionResults:243 - Found bean property 'location' of type [java.lang.String]
10:20:56,656 DEBUG CachedIntrospectionResults:243 - Found bean property 'parse' of type [boolean]
10:20:56,703 DEBUG ServletDispatcherResult:113 - Forwarding to location /MyJsp.jsp
10:20:56,750 DEBUG InstantiatingNullHandler:72 - Entering nullPropertyValue [target=[com.linkage.action.ErrorMsgSendAction@c042ab, com.opensymphony.xwork2.DefaultTextProvider@150ed68], property=org]
10:21:06,968 DEBUG I18nInterceptor:145 - after Locale=zh_CN
10:21:06,968 DEBUG I18nInterceptor:149 - intercept }
我仅仅是在MyJsp页面上有一个按钮用来提交到action,action里写了一个测试的方法如下
public String abc(){
System.out.println("abc");
return "abc";
}
现在的问题是每次执行到return 语句后就会出现上面的异常。这个异常只有在debug下才出现,在info下不会出现。并且这个异常不影响项目的运行。我在网上也搜了一下这个异常,但是没看到有解决方案。有哪位大侠遇到过这个情况吗?求助。
...全文
470 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiankewuming 2011-12-05
  • 打赏
  • 举报
回复
问题已经解决,因为我是在action中通过getBean的方式与spring整合。struts2-spring-plugin-2.0.14.jar包在项目中就是多余的。就是因为这个包一直导致出现上面的异常。我去掉这个包后就解决了。当然了,也可以通过将action交给spring的方式解决这个问题。谢谢大家。结贴。
jiankewuming 2011-12-05
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 zichuanxiu386295670 的回复:]

问题的原因应该是spring没有管理struts,
在 你的struts的配置文件中加入这样一条常量
<constant name="struts.objectFactory" value="spring" />
让spring来管理你的struts就OK了
你先看下把 如果还有问题在解决

<!-- 常量配置 -->
<constant name="struts.i18n.enc……
[/Quote]确实很详细。谢谢。
jiankewuming 2011-12-05
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 lxbccsu 的回复:]

看来看去,你在哪里整合了Struts2 和 Spring?
显然是你没有整合S2和Spring,Srping根本就没有管理你的action,
所以你的请求给Strust2 action,然后Strust2处理完相应请求响应返回;Spring却不知如何处理;
那些日志信息全是Spring给出的,显然是你在web.xml设置了spring来监听请求;
[/Quote]
我是在action中通过getBean的方式与spring整合。
  • 打赏
  • 举报
回复
问题的原因应该是spring没有管理struts,
在 你的struts的配置文件中加入这样一条常量
<constant name="struts.objectFactory" value="spring" />
让spring来管理你的struts就OK了
你先看下把 如果还有问题在解决

<!-- 常量配置 -->
<constant name="struts.i18n.encoding" value="UTF-8" />
<constant name="struts.ui.theme" value="simple" />
<constant name="struts.objectFactory" value="spring" />
我的配置通常都有这三条常量
第一:设置编码格式
第二:去掉struts自带标签的样式
第三:使用spring来管理struts
够详细了把 给点分把 哪怕五分都行!
lxbccsu 2011-12-05
  • 打赏
  • 举报
回复
看来看去,你在哪里整合了Struts2 和 Spring?
显然是你没有整合S2和Spring,Srping根本就没有管理你的action,
所以你的请求给Strust2 action,然后Strust2处理完相应请求响应返回;Spring却不知如何处理;
那些日志信息全是Spring给出的,显然是你在web.xml设置了spring来监听请求;
jiankewuming 2011-12-05
  • 打赏
  • 举报
回复
以前的帖子,问题是一样的。http://java.ygman.com/thread/74890
jiankewuming 2011-12-05
  • 打赏
  • 举报
回复
我的qq 694123415
jiankewuming 2011-12-05
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 redlotus_lyn 的回复:]

QQ:75425364

帮你看看。
[/Quote]哥,对方拒绝被添加。
redlotus_lyn 2011-12-05
  • 打赏
  • 举报
回复
QQ:75425364

帮你看看。
jiankewuming 2011-12-05
  • 打赏
  • 举报
回复
spring配置数据库等的文件
<?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.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">


<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:ess.properties</value>
</list>
</property>
</bean>
<!-- 事务配置 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<description>Spring 事务管理</description>
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 配置事务特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="sendMsg" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>

<!-- 配置哪些类的方法需要进行事务管理 -->
<aop:config>
<aop:advisor advice-ref="txAdvice"
pointcut="execution(* com.linkage.service..*.*(..))" />
</aop:config>


<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>${ess.jdbc.driverClassName}</value>
</property>
<property name="url">
<value>${ess.jdbc.url}</value>
</property>
<property name="username">
<value>${ess.jdbc.username}</value>
</property>
<property name="password">
<value>${ess.jdbc.password}</value>
</property>
<property name="maxActive">
<value>${ess.jdbc.maxActive}</value>
</property>
<property name="maxIdle">
<value>${ess.jdbc.maxIdle}</value>
</property>
<property name="maxWait">
<value>${ess.jdbc.maxWait}</value>
</property>
<property name="defaultAutoCommit">
<value>${ess.jdbc.defaultAutoCommit}</value>
</property>
<property name="removeAbandoned">
<value>${ess.jdbc.removeAbandoned}</value>
</property>
<property name="removeAbandonedTimeout">
<value>${ess.jdbc.removeAbandonedTimeout}</value>
</property>
<property name="logAbandoned">
<value>${ess.jdbc.logAbandoned}</value>
</property>
<property name="testOnBorrow" value="true" />
<property name="testWhileIdle" value="true" />
<property name="validationQuery" value="select 1 from dual" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<description>springJDBC模板类</description>
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
jiankewuming 2011-12-05
  • 打赏
  • 举报
回复
spring配置文件
<?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">
<!--错单日志查询start-->
<bean id="errorMsgSendDao" class="com.linkage.dao.impl.ErrorMsgSendDaoImpl">
<property name="jdbcTemplate">
<ref bean="jdbcTemplate"/>
</property>
</bean>
<bean id="errMsgSendService" class="com.linkage.service.impl.ErrorMsgSendServiceImpl" dependency-check="all">
<property name="errorMsgSendDao">
<ref bean="errorMsgSendDao"/>
</property>
<property name="forwardUrl">
<value>${term_ws}</value>
</property>
</bean>
<!--错单日志查询end-->
</beans>
jiankewuming 2011-12-05
  • 打赏
  • 举报
回复
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.i18n.encoding" value="UTF-8"/>
<package name="strutsbase" extends="struts-default" namespace="/errmsgsend">
<!--错单日志查询start-->
<action name="errorMsgSend*" class="com.linkage.action.ErrorMsgSendAction" method="{1}">
<result name="success">/index.jsp</result>
<result name="abc">/MyJsp.jsp</result>
</action>
<!--错单日志查询end-->
</package>
</struts>
kouyiSC 2011-12-05
  • 打赏
  • 举报
回复
一眼看上去 配置全乱套了。。。贴上来。。看看。。。
xiaoqiuwyh 2011-12-05
  • 打赏
  • 举报
回复
把你的struts.xml文件还有其它配置文件帖上来看看。

81,114

社区成员

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

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