struts2启动报错com/opensymphony/xwork2/spring/SpringObjectFactory.java:220:-1

阅读更多

好久没有搞struts2,今天配置strut2.2.1,启动时遇到个小问题。记录下。

tomcat启动报错:

Class: com.opensymphony.xwork2.spring.SpringObjectFactory
File: SpringObjectFactory.java
Method: getClassInstance
Line: 220 - com/opensymphony/xwork2/spring/SpringObjectFactory.java:220:-1
	at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:428)
	at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
	at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
	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.(ApplicationFilterConfig.java:115)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3838)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4488)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
	at org.apache.catalina.core.StandardService.start(StandardService.java:519)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
	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:585)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.NullPointerException
	at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:220)

 

原因:

配置了依赖:

		
			org.apache.struts
			struts2-spring-plugin
			2.2.1
		

但是工程web.xml中没有配置加载spring ApplicationContext相关的listener


	
		org.springframework.web.context.ContextLoaderListener
	

原理:

查看struts2插件struts2-spring-plugin中的strtus-plugin.xml


    
    
    
    


    
    
    

    
        
            
            
        
        

 

 注意下面部分,表明该插件引入工程后,会自动设置Struts的ObjectFactory为StrutsSpringObjectFactory,从而让Spring的IOC容器来托管Struts的Action。所以导致了启动的问题。

 

    
    
     

    

记录一下错误,方便查看。

 

你可能感兴趣的:(Spring,Java,Apache,Struts,Bean)