-2

我正在使用 Struts 2 和 Spring 3。我无法注入 bean 并RunTimeException开始启动struts2过滤器。我正在使用以下 jar 文件

servlet-api-2.4.jar、struts2-spring-plugin-2.1.6.jar、struts2-spring-plugin-2.1.6.jar、org.springframework.beans-3.0.0.M3.jar、xwork-2.0。 2.jar、struts2-core-2.0.12.jar等

SEVERE: Exception starting filter struts2
    java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='struts.objectFactory.spring.autoWire.alwaysRespect'] in public org.apache.struts2.spring.StrutsSpringObjectFactory(java.lang.String,java.lang.String,java.lang.String,javax.servlet.ServletContext).
        at com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.inject(ContainerImpl.java:290)
        at com.opensymphony.xwork2.inject.ContainerImpl$2.call(ContainerImpl.java:117)
        at com.opensymphony.xwork2.inject.ContainerImpl$2.call(ContainerImpl.java:115)
        at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:542)
        at com.opensymphony.xwork2.inject.ContainerImpl.injectStatics(ContainerImpl.java:114)
        at com.opensymphony.xwork2.inject.ContainerBuilder.create(ContainerBuilder.java:494)
        at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reload(DefaultConfiguration.java:145)
        at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:52)
        at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:395)
        at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:452)
        at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:205)
        at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
        at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
        at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4071)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4725)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
        at org.apache.catalina.core.StandardService.start(StandardService.java:525)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
    Caused by: java.lang.RuntimeException: java.lang.RuntimeException: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='struts.objectFactory.spring.autoWire.alwaysRespect'] in public org.apache.struts2.spring.StrutsSpringObjectFactory(java.lang.String,java.lang.String,java.lang.String,javax.servlet.ServletContext).
        at com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:136)
        at com.opensymphony.xwork2.inject.Scope$2$1.create(Scope.java:49)
        at com.opensymphony.xwork2.inject.ContainerImpl$ParameterInjector.inject(ContainerImpl.java:431)
        at com.opensymphony.xwork2.inject.ContainerImpl.getParameters(ContainerImpl.java:446)
        at com.opensymphony.xwork2.inject.ContainerImpl.access$000(ContainerImpl.java:48)
        at com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.inject(ContainerImpl.java:288)
        ... 28 more
    Caused by: java.lang.RuntimeException: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='struts.objectFactory.spring.autoWire.alwaysRespect'] in public org.apache.struts2.spring.StrutsSpringObjectFactory(java.lang.String,java.lang.String,java.lang.String,javax.servlet.ServletContext).
        at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:464)
        at com.opensymphony.xwork2.inject.ContainerImpl$7.call(ContainerImpl.java:501)
        at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:549)
        at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:499)
        at com.opensymphony.xwork2.config.impl.LocatableFactory.create(LocatableFactory.java:32)
        at com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:134)
        ... 33 more
    Caused by: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='struts.objectFactory.spring.autoWire.alwaysRespect'] in public org.apache.struts2.spring.StrutsSpringObjectFactory(java.lang.String,java.lang.String,java.lang.String,javax.servlet.ServletContext).
        at com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector.<init>(ContainerImpl.java:327)
        at com.opensymphony.xwork2.inject.ContainerImpl$5.create(ContainerImpl.java:299)
        at com.opensymphony.xwork2.inject.ContainerImpl$5.create(ContainerImpl.java:298)
        at com.opensymphony.xwork2.inject.util.ReferenceCache$CallableCreate.call(ReferenceCache.java:155)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at com.opensymphony.xwork2.inject.util.ReferenceCache.internalCreate(ReferenceCache.java:81)
        at com.opensymphony.xwork2.inject.util.ReferenceCache.get(ReferenceCache.java:121)
        at com.opensymphony.xwork2.inject.ContainerImpl.getConstructor(ContainerImpl.java:562)
        at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:460)
        ... 38 more
    Caused by: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='struts.objectFactory.spring.autoWire.alwaysRespect'] in public org.apache.struts2.spring.StrutsSpringObjectFactory(java.lang.String,java.lang.String,java.lang.String,javax.servlet.ServletContext).
        at com.opensymphony.xwork2.inject.ContainerImpl.createParameterInjector(ContainerImpl.java:239)
        at com.opensymphony.xwork2.inject.ContainerImpl.getParametersInjectors(ContainerImpl.java:229)
        at com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector.<init>(ContainerImpl.java:318)
        ... 47 more
    5 Mar, 2013 6:14:01 PM org.apache.catalina.core.StandardContext start
    SEVERE: Error filterStart
    5 Mar, 2013 6:14:01 PM org.apache.catalina.core.StandardContext start
    SEVERE: Context [/Fundation] startup failed due to previous errors
    5 Mar, 2013 6:14:01 PM org.apache.catalina.core.ApplicationContext log
    INFO: Closing Spring root WebApplicationContext
    5 Mar, 2013 6:14:01 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
    SEVERE: The web application [/Fundation] registered the JDBC driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
    5 Mar, 2013 6:14:01 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
    SEVERE: The web application [/Fundation] registered the JDBC driver [oracle.jdbc.driver.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
    5 Mar, 2013 6:14:01 PM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
    SEVERE: The web application [/Fundation] created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.ContainerImpl$10] (value [com.opensymphony.xwork2.inject.ContainerImpl$10@7f162a9c]) and a value of type [com.opensymphony.xwork2.inject.InternalContext[]] (value [[Lcom.opensymphony.xwork2.inject.InternalContext;@847a8f3]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
    5 Mar, 2013 6:14:02 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
    INFO: validateJarFile(D:\eclipse-indigo\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\SpringMVCTutorial\WEB-INF\lib\servlet-api-2.4.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
    5 Mar, 2013 6:14:02 PM org.apache.catalina.core.ApplicationContext log
    INFO: Initializing Spring FrameworkServlet 'SpringMVCTutorial'
    5 Mar, 2013 6:14:02 PM org.springframework.web.servlet.FrameworkServlet initServletBean
    INFO: FrameworkServlet 'SpringMVCTutorial': initialization started
    5 Mar, 2013 6:14:02 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
    INFO: Refreshing org.springframework.web.context.support.XmlWebApplicationContext@1b83ee9a: display name [WebApplicationContext for namespace 'SpringMVCTutorial-servlet']; startup date [Tue Mar 05 18:14:02 IST 2013]; root of context hierarchy
    5 Mar, 2013 6:14:02 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/SpringMVCTutorial-servlet.xml]
    5 Mar, 2013 6:14:02 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
    INFO: Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@1b83ee9a]: org.springframework.beans.factory.support.DefaultListableBeanFactory@12f53870
    5 Mar, 2013 6:14:02 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@12f53870: defining beans [viewResolver,/welcome.htm,springMessage,message]; root of factory hierarchy
    5 Mar, 2013 6:14:02 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
    INFO: Mapped URL path [/welcome.htm] onto handler [com.cpt.spring.HelloWorldController@1aad40a0]
    5 Mar, 2013 6:14:02 PM org.springframework.web.servlet.FrameworkServlet initServletBean
4

3 回答 3

1

将 servlet 规范至少更改为 2.4,spring 插件也应该与 spring 库一起使用。如果它没有帮助使用struts.objectFactory.spring.autoWire.alwaysRespect=false默认的常量。

于 2013-03-05T17:56:09.837 回答
1

你必须用最新的升级你的struts2核心 jar 和xworkjar。使用不同版本的 stuts2core 和 struts2spring jar 可能会出现问题。

希望这对你有帮助

于 2013-03-06T03:51:04.853 回答
-1

我已经解决了这个问题。您首先提取 struts-spring 插件。在里面struts2-spring-plugin-x.y.z.jar\org\apache\struts2\spring你会发现StrutsSpringObjectFactory.class. 使用任何类编辑器,您都可以打开这个 .class 文件。

在那里你会看到 @Inject(value=StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_AUTOWIRE_ALWAYS_RESPECT,required=false) 行

字符串 alwaysAutoWire 存在。最后,方法调用

this.setAlwaysRespectAutowireStrategy("true".equalsIgnoreCase(alwaysAutoWire));

存在导致问题。实际上这个方法调用不能映射到一个有效的 setter 方法,因此NoSuchMethodError.

现在,要解决问题,请下载 struts2-spring-plugin-2.0.11.1.jar 并将其添加到项目的 lib 中。如果您按照上述过程检查此 jar,您将找不到该 setter 调用,因此不会发生错误。希望对你有效。

于 2015-03-26T18:24:11.973 回答