我正在使用項目和GlassFish v2.1的Maven結構來執行此應用程序。Spring MVC 4 Hello World StandardWrapper.Throwable java.lang.NullPointerException
我的pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.spring.proj3</groupId>
<artifactId>Spring4MVCApp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Spring4MVCApp Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<java-version>1.7</java-version>
<org.springframework-version>4.0.3.RELEASE</org.springframework-version>
<org.springframework.security-version>3.2.3.RELEASE</org.springframework.security-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
<!-- Spring -->
<!-- Spring Dependencies -->
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
<finalName>SpringSample2</finalName>
</build>
我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
調度-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-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.javahash.spring.controller" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
控制器
package com.javahash.spring.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class HelloWorldController {
@RequestMapping("/hello")
public String hello(
@RequestParam(value = "name", required = false, defaultValue = "World") String name,
Model model) {
model.addAttribute("name", name);
return "helloworld";
}
}
我的問題:
無法部署代碼獲得上述錯誤的稱號。
步驟嘗試:
(一)修改web.xml中時的頂配版本 - 沒有工作 (二)不同的,更春末的版本。
這裏什麼都不起作用。
堆棧跟蹤
Severe: WebModule[/Spring4MVCApp]StandardWrapper.Throwable
java.lang.NullPointerException
at org.springframework.core.SerializableTypeWrapper$TypeProxyInvocationHandler.invoke(SerializableTypeWrapper.java:239)
at org.springframework.core.$Proxy34.hashCode(Unknown Source)
at org.springframework.util.ObjectUtils.nullSafeHashCode(ObjectUtils.java:273)
at org.springframework.core.ResolvableType.hashCode(ResolvableType.java:794)
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:1169)
at org.springframework.core.ResolvableType.forType(ResolvableType.java:1148)
at org.springframework.core.ResolvableType.forTypes(ResolvableType.java:827)
at org.springframework.core.ResolvableType.getInterfaces(ResolvableType.java:403)
at org.springframework.core.ResolvableType.as(ResolvableType.java:365)
Severe: WebModule[/Spring4MVCApp]PWC1396: Servlet /Spring4MVCApp threw load() exception
java.lang.NullPointerException
at org.springframework.core.SerializableTypeWrapper$TypeProxyInvocationHandler.invoke(SerializableTypeWrapper.java:239)
at org.springframework.core.$Proxy34.hashCode(Unknown Source)
at org.springframework.util.ObjectUtils.nullSafeHashCode(ObjectUtils.java:273)
at org.springframework.core.ResolvableType.hashCode(ResolvableType.java:794)
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:1169)
at org.springframework.core.ResolvableType.forType(ResolvableType.java:1148)
at org.springframework.core.ResolvableType.forTypes(ResolvableType.java:827)
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)
Severe: ContainerBase.addChild: start:
LifecycleException: java.lang.NullPointerException
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4927)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5324)
at com.sun.enterprise.web.WebModule.start(WebModule.java:353)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:989)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:973)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:704)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1627)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1232)
at com.sun.enterprise.server.WebModuleDeployEventListener.moduleDeployed(WebModuleDeployEventListener.java:182)
at com.sun.enterprise.server.WebModuleDeployEventListener.moduleDeployed(WebModuleDeployEventListener.java:278)
at com.sun.enterprise.admin.event.AdminEventMulticaster.invokeModuleDeployEventListener(AdminEventMulticaster.java:1005)
at com.sun.enterprise.admin.event.AdminEventMulticaster.handleModuleDeployEvent(AdminEventMulticaster.java:992)
at com.sun.enterprise.admin.event.AdminEventMulticaster.processEvent(AdminEventMulticaster.java:470)
at com.sun.enterprise.admin.event.AdminEventMulticaster.multicastEvent(AdminEventMulticaster.java:182)
at com.sun.enterprise.admin.server.core.DeploymentNotificationHelper.multicastEvent(DeploymentNotificationHelper.java:308)
at com.sun.enterprise.deployment.phasing.DeploymentServiceUtils.multicastEvent(DeploymentServiceUtils.java:231)
at com.sun.enterprise.deployment.phasing.ServerDeploymentTarget.sendStartEvent(ServerDeploymentTarget.java:298)
at com.sun.enterprise.deployment.phasing.ApplicationStartPhase.runPhase(ApplicationStartPhase.java:132)
出現剪切數低於他們每個人由於空間的限制
張貼堆棧跟蹤 –
請檢查現在的問題@JigarJoshi – swateek
您排除'公地logging'(你應該從'彈簧core'不'彈簧context'排除使它棒),但不要不包括SLF4J(根據您要使用的評論來判斷)。你也在使用一個非常古老的應用服務器,你真的需要glassfish嗎?嘗試一個普通的tomcat。 –