我正在使用struts2应用程序,但它要求弹簧配置

时间:2013-06-17 11:23:57

标签: struts2

当我尝试从沙箱中单独运行配员示例时,我收到以下错误。

错误如下:

You might need to add the following to web.xml: 
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Jun 17, 2013 7:17:39 AM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter struts2
java.lang.NullPointerException
    at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:188)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyResultType(XmlConfigurationProvider.java:479)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addResultTypes(XmlConfigurationProvider.java:450)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:407)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:239)
    at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111)
    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reload(DefaultConfiguration.java:152)
    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: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:4072)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4726)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    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(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

的web.xml:

    <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
        <init-param>
            <param-name>actionPackages</param-name>
            <param-value>manning</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <servlet>
        <servlet-name>anotherServlet</servlet-name>
        <servlet-class>manning.servlet.AnotherServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>anotherServlet</servlet-name>
        <url-pattern>/anotherServlet</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

struts.xml中

    <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

   <!--
            For the purposes of the book, we will leave devMode set to true.  This
            allows several things to occur including provision of debugging level information
            on error pages as well as reloading of various resources with each request.
   --> 
   <constant name="struts.devMode" value="true" />
        <!-- 
            You can define packages directly in this file, but its probably best
            to modularize the configuration files with separate xml files for each
            package.  Ulitmately its all the same because the include element, seen
            below, pulls the included configuration document directly in to the 
            primary document.  The only thing to consider is that a referenced
            element must have been declared above the referring element.         
        -->

        <!-- 
                This is the menu action that will allow the reader to see the different
                samples actions from the different chapters in a menu format.  We declare
                it here, in the root namespace, because its not really related to any of the
                specific examples or chapters, its just a kind of utility for the whole 
                application.
        -->
        <package name="default" namespace="/" extends="struts-default"> 
            <action name="Menu">
                <result>/menu/Menu.jsp</result>
            </action>
        </package>  

    <include file="manning/chapterTwo/chapterTwo.xml"/>
    <include file="manning/chapterThree/chapterThree.xml"/>  
    <include file="manning/chapterThree/objectBacked/chapterThree.xml"/>
    <include file="manning/chapterThree/modelDriven/chapterThree.xml"/>
    <include file="manning/chapterFour/chapterFour.xml"/>  
    <include file="manning/chapterFive/chapterFive.xml"/>  
    <include file="manning/chapterSix/chapterSix.xml"/>  
    <include file="manning/chapterSeven/chapterSeven.xml"/>  
    <include file="manning/chapterEight/chapterEight.xml"/>  
    <include file="manning/chapterNine/chapterNine.xml"/>  
    <include file="manning/chapterTen/chapterTen.xml"/>  
    <include file="manning/chapterEleven/chapterEleven.xml"/>  


</struts>

为什么我收到错误。我在web.xml中删除了一些关于spring的配置

1 个答案:

答案 0 :(得分:0)

将过滤器更改为

<filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

如果你的类路径中有这个jar并且不想使用Spring与Struts2的集成,那么从classpath中删除struts2-spring-plugin - * .jar

如果您仍然面临问题,请告诉我