今天学习了webwork与spring的集成,出现的莫名错误。
webwork与spring集成一共有三种方法,1.External-Ref ,2.SpringObjectFactory ,3.ActionAutowiringInterceptor 。第三种方法比较简洁,但是在使用的时候出现问题。
第一步:配置web.xml
xml 代码
- <listener>
- <listener-class>org.springframwork.web.context.ContextLoaderListener</listener-class>
- </listener>
修改webwork.properties加入
webwork.objectFactory = spring
第二步配置xwork.xml里面的拦截器
xml 代码
- <interceptor name="autowire" class="com.opensymphony.xwork.spring.interceptor.ActionAutowiringInterceptor">
- <param name="autowireStrategy">
- @org.springframework.beans.factory.config.AutowireCapableBeanFactory@AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE
- </param>
- </interceptor>
按照上面的步骤配置完后,运行程序时出现以下警告:
java 代码
- 警告: Caught OgnlException while setting property 'autowireStrategy' on type 'com.opensymphony.xwork.spring.interceptor.ActionAutowiringInterceptor'.
- java.lang.NoSuchMethodException: setAutowireStrategy(java.lang.String)
- at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:783)
- at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:937)
- at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:76)
- at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:132)
- at com.opensymphony.xwork.util.OgnlValueStack$ObjectAccessor.setProperty(OgnlValueStack.java:64)
- at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1629)
- at ognl.ASTProperty.setValueBody(ASTProperty.java:105)
- at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)
- at ognl.SimpleNode.setValue(SimpleNode.java:246)
- at ognl.Ognl.setValue(Ognl.java:476)
- at com.opensymphony.xwork.util.OgnlUtil.setValue(OgnlUtil.java:186)
- at com.opensymphony.xwork.util.OgnlUtil.internalSetProperty(OgnlUtil.java:360)
- at com.opensymphony.xwork.util.OgnlUtil.setProperties(OgnlUtil.java:76)
- at com.opensymphony.xwork.util.OgnlUtil.setProperties(OgnlUtil.java:103)
- at com.opensymphony.xwork.util.OgnlUtil.setProperties(OgnlUtil.java:90)
- at com.opensymphony.xwork.ObjectFactory.buildInterceptor(ObjectFactory.java:150)
- at com.opensymphony.xwork.config.providers.InterceptorBuilder.constructInterceptorReference(InterceptorBuilder.java:48)
- at com.opensymphony.xwork.config.providers.XmlConfigurationProvider.lookupInterceptorReference(XmlConfigurationProvider.java:702)
- at com.opensymphony.xwork.config.providers.XmlConfigurationProvider.loadInterceptorStack(XmlConfigurationProvider.java:569)
- at com.opensymphony.xwork.config.providers.XmlConfigurationProvider.loadInterceptorStacks(XmlConfigurationProvider.java:582)
- at com.opensymphony.xwork.config.providers.XmlConfigurationProvider.loadInterceptors(XmlConfigurationProvider.java:603)
- at com.opensymphony.xwork.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:204)
- at com.opensymphony.xwork.config.providers.XmlConfigurationProvider.loadConfigurationFile(XmlConfigurationProvider.java:676)
- at com.opensymphony.xwork.config.providers.XmlConfigurationProvider.init(XmlConfigurationProvider.java:91)
- at com.opensymphony.xwork.config.impl.DefaultConfiguration.reload(DefaultConfiguration.java:85)
- at com.opensymphony.xwork.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:54)
- at com.opensymphony.xwork.DefaultActionProxy.(DefaultActionProxy.java:57)
- at com.opensymphony.xwork.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:46)
- at com.opensymphony.webwork.dispatcher.DispatcherUtils.serviceAction(DispatcherUtils.java:216)
- at com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:111)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
- at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
- at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
- at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
- at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
- at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
- at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
- at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
- at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
- at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
- at java.lang.Thread.run(Thread.java:595)
- ********************
不知道是什么原因,web容器启动时,日志显示webwork与spring集成成功,我使用的包是webwork2.2.4,spring是2.0.4,服务器是tomcat6.0。
希望有遇到过这样问题的同志给予解答!