问题描述
SSH整合DWR时,出现如下错误,好像是使用dwr调用后台的类时不能通过spring实例化该类,报错如下:java.lang.NoClassDefFoundError:org/springframework/web/servlet/support/RequestContextUtilsatorg.directwebremoting.spring.SpringCreator.getBeanFactory(SpringCreator.java:173)atorg.directwebremoting.spring.SpringCreator.getInstance(SpringCreator.java:131)atorg.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:333)atorg.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:273)atorg.directwebremoting.servlet.PlainCallHandler.handle(PlainCallHandler.java:52)atorg.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:101)atorg.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:120)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:710)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:803)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)atorg.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:73)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)atorg.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)atorg.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)atorg.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)atorg.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)atorg.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)atorg.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)atorg.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)atjava.lang.Thread.run(UnknownSource)我的web.xml配置:<listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class><!--default:/WEB-INF/applicationContext.xml--></listener><context-param><param-name>contextConfigLocation</param-name><!--<param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>--><param-value>classpath:beans.xml</param-value></context-param><filter><filter-name>encodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param></filter><filter-mapping><filter-name>encodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><filter><filter-name>openSessionInView</filter-name><filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class><init-param><param-name>sessionFactoryBeanName</param-name><param-value>sf</param-value></init-param></filter><filter-mapping><filter-name>openSessionInView</filter-name><url-pattern>/*</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>/*</url-pattern></filter-mapping><!--配置DWR--><servlet><servlet-name>dwr-invoker</servlet-name><servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class><init-param><param-name>debug</param-name><param-value>true</param-value></init-param><init-param><param-name>allowGetForSafariButMakeForgeryEasier</param-name><param-value>true</param-value></init-param><load-on-startup>2</load-on-startup></servlet><servlet-mapping><servlet-name>dwr-invoker</servlet-name><url-pattern>/dwr/*</url-pattern></servlet-mapping><!--配置DWR结束-->dwr.xml配置:<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdwrPUBLIC"-//GetAheadLimited//DTDDirectWebRemoting2.0//EN""http://getahead.org/dwr/dwr20.dtd"><dwr><allow><createjavascript="TuanSiteManagerImplJs"creator="spring"><paramname="class"value="com.sp.service.impl.TuanSiteManagerImpl"></param><includemethod="deleteById"/></create></allow></dwr>spring中的注入使用声明的方式,这些注入在不适用dwr时都正常。类的代码:@Component("tuanSiteManagerImpl")publicclassTuanSiteManagerImplimplementsTuanSiteManager{privateTuanSiteDaoTuanSiteDao;publicTuanSiteDaogetTuanSiteDao(){returnTuanSiteDao;}@ResourcepublicvoidsetTuanSiteDao(TuanSiteDaoTuanSiteDao){this.TuanSiteDao=TuanSiteDao;}publicvoiddelete(TuanSiteobj){//TODOAuto-generatedmethodstubTuanSiteDao.delete(obj);}publicvoiddeleteAbsolute(TuanSiteobj){//TODOAuto-generatedmethodstubTuanSiteDao.deleteAbsolute(obj);}publicbooleandeleteById(intid){//TODOAuto-generatedmethodstubbooleanflag=false;//try{TuanSiteobj=TuanSiteDao.getById(id);TuanSiteDao.delete(obj);flag=true;//}catch(Exceptione){//TODO:handleexceptionflag=false;//System.out.println(e.getMessage());//}returnflag;}}使用的是dwr2.0版本,使用3.0版本的时候能找到该类,但是其注入的dao类为空,不能获得其实例请高手指点,万分感谢!
解决方案
解决方案二:
<paramname="beanName"value="spring里面beanName"/>例如<createcreator="spring"javascript="JGetUserInfo"><paramname="beanName"value="userInfoBiz"/><includemethod="ixExits"/><!--修改--><includemethod="ixExitsN"/><!--注册--></create>
解决方案三:
缺少spring-webmvc-1.0.jar
解决方案四:
引用1楼weihui5368452的回复:
<paramname="beanName"value="spring里面beanName"/>例如<createcreator="spring"javascript="JGetUserInfo"><paramname="beanName"value="userInfoBiz"/><includemethod="ixExits"/><!--修改--><in……
这样改了之后提示:Classnotfound:tuanSiteManagerImpl,还是不行啊