我正在尝试在Eclipse Luna中设置动态Web项目。我已经将Tomcat 8服务器设置为能够部署到该服务器。我有一个试图部署的小型Spring MVC(春季4)项目。当我这样做时,出现以下异常:

Aug 27, 2014 12:52:52 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /SponsoredNetIDs threw load() exception
java.lang.NullPointerException
    at org.springframework.core.SerializableTypeWrapper$TypeProxyInvocationHandler.invoke(SerializableTypeWrapper.java:239)
    at org.springframework.core.$Proxy4.hashCode(Unknown Source)
    at org.springframework.util.ObjectUtils.nullSafeHashCode(ObjectUtils.java:273)
    at org.springframework.core.ResolvableType.hashCode(ResolvableType.java:811)
    at org.springframework.util.ConcurrentReferenceHashMap.getHash(ConcurrentReferenceHashMap.java:214)
    at org.springframework.util.ConcurrentReferenceHashMap.getReference(ConcurrentReferenceHashMap.java:246)
    at org.springframework.util.ConcurrentReferenceHashMap.get(ConcurrentReferenceHashMap.java:226)
    at org.springframework.core.ResolvableType.forType(ResolvableType.java:1186)
    at org.springframework.core.ResolvableType.forType(ResolvableType.java:1165)
    at org.springframework.core.ResolvableType.forTypes(ResolvableType.java:844)
    at org.springframework.core.ResolvableType.getInterfaces(ResolvableType.java:403)
    at org.springframework.core.ResolvableType.as(ResolvableType.java:365)
    at org.springframework.core.convert.support.GenericConversionService.getRequiredTypeInfo(GenericConversionService.java:266)
    at org.springframework.core.convert.support.GenericConversionService.addConverterFactory(GenericConversionService.java:103)
    at org.springframework.core.convert.support.DefaultConversionService.addScalarConverters(DefaultConversionService.java:79)
    at org.springframework.core.convert.support.DefaultConversionService.addDefaultConverters(DefaultConversionService.java:63)
    at org.springframework.core.convert.support.DefaultConversionService.<init>(DefaultConversionService.java:50)
    at org.springframework.core.env.AbstractPropertyResolver.<init>(AbstractPropertyResolver.java:41)
    at org.springframework.core.env.PropertySourcesPropertyResolver.<init>(PropertySourcesPropertyResolver.java:41)
    at org.springframework.core.env.AbstractEnvironment.<init>(AbstractEnvironment.java:112)
    at org.springframework.core.env.StandardEnvironment.<init>(StandardEnvironment.java:54)
    at org.springframework.web.context.support.StandardServletEnvironment.<init>(StandardServletEnvironment.java:44)
    at org.springframework.web.servlet.HttpServletBean.createEnvironment(HttpServletBean.java:215)
    at org.springframework.web.servlet.HttpServletBean.getEnvironment(HttpServletBean.java:205)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:126)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1241)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1154)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1041)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4923)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5209)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)


我为此使用Maven 3.2.3

我的POM文件如下所示:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <!-- The Basics -->
    <groupId>com.company</groupId>
    <artifactId>sponsorednetids</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <!-- Project Information -->
    <name>Sponsored NetID</name>

    <!-- The Build -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <webXml>WebRoot\WEB-INF\web.xml</webXml>
                    <webResources>
                        <resource>
                            <directory>src\main\resources</directory>
                        </resource>
                    </webResources>
                    <archive>
                        <manifest>
                          <addClasspath>true</addClasspath>
                        </manifest>
                      </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <!-- Dependencies -->
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring-webmvc.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring-web.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>${commons-lang.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>${commons-logging.version}</version>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>${jstl.version}</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${servlet-api.version}</version>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>${taglibs-standard.version}</version>
        </dependency>
    </dependencies>

    <!-- Environment Settings -->
    <properties>
        <junit.version>4.11</junit.version>
        <spring-webmvc.version>4.0.6.RELEASE</spring-webmvc.version>
        <spring-web.version>4.0.6.RELEASE</spring-web.version>
        <spring.version>2.5.6</spring.version>
        <commons-lang.version>2.6</commons-lang.version>
        <commons-logging.version>1.2</commons-logging.version>
        <jstl.version>1.2</jstl.version>
        <log4j.version>1.2.17</log4j.version>
        <servlet-api.version>3.1.0</servlet-api.version>
        <taglibs-standard.version>1.1.2</taglibs-standard.version>
    </properties>
</project>


servlet.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-4.0.xsd">

    <context:component-scan base-package="com.company.sponsorednetids.controller" />

    <bean class="com.company.sponsorednetids.controller.InitiatorDashboardValidator" />

    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename" value="messages" />
    </bean>

    <bean id="exceptionResolver" class="com.company.controller.ExceptionHandler">
        <property name="errorView" value="exception"/>
    </bean>

    <!-- Special id known to ModelAndView in Spring, which can map JSPs to the prefix below -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="view.html">initiatorDashboardController</prop>
            </props>
        </property>
    </bean>
</beans>


最后是我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
    <display-name>Sponsored Net IDs</display-name>
    <context-param>
        <param-name>webAppRootKey</param-name>
        <param-value>sponsorednetids.root</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>sponsorednetids</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>sponsorednetids</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <session-config>
        <session-timeout>60</session-timeout>
    </session-config>
</web-app>


当我转到Eclipse中的项目时,右键单击并转到“在服务器上调试”,将引发异常。那是在启动过程中。

感谢您的帮助!

最佳答案

我想通了。问题在于春天的依赖关系:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
    <version>${spring.version}</version>
</dependency>


我只需要删除它就可以了!

关于java - 使用Maven将Spring MVC移植到Tomcat 8上:NullPointerException with SerializableTypeWrapper,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25533211/

10-11 03:47