日期:2014-05-18  浏览次数:20773 次

struts2.0借助spring实现IoC出错
错误提示如下(MyEclipse):
严重:   Exception   starting   filter   struts2
Cannot   locate   the   chosen   ObjectFactory   implementation:   spring   -   [unknown   location]
at   org.apache.struts2.config.BeanSelectionProvider.alias(BeanSelectionProvider.java:223)
at   org.apache.struts2.config.BeanSelectionProvider.alias(BeanSelectionProvider.java:194)
at   org.apache.struts2.config.BeanSelectionProvider.register(BeanSelectionProvider.java:153)
at   com.opensymphony.xwork2.config.impl.DefaultConfiguration.reload(DefaultConfiguration.java:131)
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:201)
at   org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:223)
at   org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:304)
at   org.apache.catalina.core.ApplicationFilterConfig. <init> (ApplicationFilterConfig.java:77)
at   org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3634)
at   org.apache.catalina.core.StandardContext.start(StandardContext.java:4217)
at   org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1089)
at   org.apache.catalina.startup.HostConfig.check(HostConfig.java:1187)
at   org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:292)
at   org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at   org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1305)
at   org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1569)
at   org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1578)
at   org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1558)
at   java.lang.Thread.run(Thread.java:595)
2007-9-23   20:00:25   org.apache.catalina.core.StandardContext   start
严重:   Error   filterStart
2007-9-23   20:00:25   org.apache.catalina.core.StandardContext   start


感觉是struts.properties文件配置出错,但不知如何修改,文件中仅有一行:
struts.objectFactory=spring

------解决方案--------------------
感觉好象是spring需要的类库没有放在lib目录下,
你可以看看这里的内容:
http://blog.csdn.net/struts2/archive/2007/08/09/1733765.aspx
------解决方案--------------------
需要在struts的配置文件中加入:
<plug-in className= "org.springframework.web.struts.ContextLoaderPlugIn ">
<set-property property= "contextConfigLocation " value= "/WEB-INF/bean-config.xml "/>
</plug-in>
才可以。