struts2+spring 问题

冯志健 发布于 2012/07/18 17:45
阅读 554
收藏 0

按默认配置 struts.xml放到 classpath下加载没问题 但是在将路径改变到其他目录下就报错了。

struts.xml

 <struts>
        <constant name="struts.objectFactory" value="spring" />
        <constant name="struts.convention.result.path" value="/WEB-INF/view"></constant>
        <constant name="struts.convention.exclude.packages" value="com.bill.exam.controller.*"></constant>
        <constant name="struts.devMode" value="true" />
    </struts>

web.xml

      <filter>
    <filter-name>struts</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
   <init-param>
        <param-name>config</param-name>
        <param-value>classpath:org/bill/exam/struts.xml</param-value>
    </init-param>
  </filter>

错误信息

    com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=com.opensymphony.xwork2.ObjectFactory, name='default'] in public void com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.setObjectFactory(com.opensymphony.xwork2.ObjectFactory).
    at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMembers(ContainerImpl.java:144)
    at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMethods(ContainerImpl.java:113)
    at com.opensymphony.xwork2.inject.ContainerImpl.addInjectors(ContainerImpl.java:90)
    at com.opensymphony.xwork2.inject.ContainerImpl.addInjectors(ContainerImpl.java:86)
    at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:71)
    at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:67)
    at com.opensymphony.xwork2.inject.util.ReferenceCache$CallableCreate.call(ReferenceCache.java:150)
    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:76)
    at com.opensymphony.xwork2.inject.util.ReferenceCache.get(ReferenceCache.java:116)
    at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:483)
    at com.opensymphony.xwork2.inject.ContainerImpl$6.call(ContainerImpl.java:523)
    at com.opensymphony.xwork2.inject.ContainerImpl$6.call(ContainerImpl.java:521)
    at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:574)
    at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:521)
    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:203)
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:380)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:424)
    at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:195)
    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)

这是什么原因呢 ??

加载中
0
JFinal
JFinal
struts 的 spring plugin 有个 jar 包,不知道楼主加进来没有
0
冯志健
加了 我在网上找到 说在 <init-param>
        <param-name>config</param-name>
        <param-value>classpath:org/bill/exam/struts.xml</param-value>

    </init-param>这初始化参数中加一个 struts-default.xml 不管这个配置文件是否存在 加上就可以了

可能struts2加载配置文件时应该 有这样一个bug

返回顶部
顶部