J'ai fait un programme simple, mais j'ai l'erreur suivante. J'utilise Eclipse Kelper et Tomcat 7.0. Essayé beaucoup de choses, mais rien ne fonctionne pour moi :(
État HTTP 500 - Servlet.init () pour le servlet loginDispacher a généré une exception
type Rapport d'exception
message Servlet.init () pour le servlet loginDispacher a levé une exception
description Le serveur a rencontré une erreur interne qui l’empêchait de répondre à cette demande.
exception
javax.servlet.ServletException: Servlet.init () pour servlet loginDispacher a levé une exception org.Apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.Java:502) org. .Apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.Java:100) Org.Apache.catalina.valves.AccessLogValve.invoke (AccessLogValve.Java:953) Org.Apache.catalina .connector.CoyoteAdapter.service (CoyoteAdapter.Java:408) org.Apache.coyote.http11.AbstractHttp11Processor.process (AbstractHttp11Processor.Java:1041) org.Ap. .process (AbstractProtocol.Java:603) org.Apache.Tomcat.util.net.JIoEndpoint $ SocketProcessor.run (JIoEndpoint.Java:312) Java.util.concurrent.ThreadExecutor.runWorker (Source inconnue) Java.util.concurrent.ThreadPoolExecutor $ Worker.run (Source inconnue) Java.lang.Thread.run (Source inconnue)
cause première
Java.lang.NoSuchMethodError: Org.springframework.core.GenericTypeResolver.resolveTypeArguments (Ljava/lang/Class; Ljava/lang/Class;) [Ljava/lang/Class; Org.springframework. core.convert.support.GenericConversionService.getRequiredTypeInfo (GenericConversionService.Java:260) org.pringframework.core.convert.support.GenericConversionService.onConverter (GenericConversion) core.convert.support.DefaultConversionService.addScalarConverters (DefaultConversionService.Java:63) org.springframework.core.convert.support.DefaultConversionService.addDefaultConverters (Default.Conversion core.convert.support.DefaultConversionService. (DefaultConversionService.Java:43) org.springframework.core.env.AbstractPropertyResolver. (AbstractPropertyResolver.Java:41) org.springframework.en. PropertySourcesPropertyResolver. (PropertySourcesPropertyResolver.Java:4 1) Org.springframework.core.env.AbstractEnvironment. (AbstractEnvironment.Java:98) Org.springframework.core.env.StandardEnvironment. (StandardEnvironment.Java:54) org.springframework.web.context.support.StandardServletEnvironment. (StandardServletEnvironment.Java:44) org.springframework.web.servlet.HttpServletBean.createEnvironment (HttpServletBean.Java) .13. springframework.web.servlet.HttpServletBean.getEnvironment (HttpServletBean.Java:203) org.springframework.web.servlet.HttpServletBean.init (HttpServletBean.Java:126) j. init (GenericServlet.Java:160) org.Apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.Java:502) . Java: 100) Org.Apache.catalina.valves.AccessLogValve.invoke (AccessLogValve.Java:953) Org.Apache.catalina.connector.CoyoteAdapter.service (Coyo teAdapter.Java:408) org.Apache.coyote.http11.AbstractHttp11Processor.process (AbstractHttp11Processor.Java:1041) .. 603) Org.Apache.Tomcat.util.net.JIoEndpoint $ SocketProcessor.run (JIoEndpoint.Java:312) Java.util.concurrent.ThreadPoolExecutor.runWorker (Source inconnue) Java.util.concurrent.ThreadPoolExecutor $ Worker.run (Source inconnue) Java.lang.Thread.run (Source inconnue)
note Remarque La trace de pile complète de la cause première est disponible dans les journaux Apache Tomcat/7.0.47.
Apache Tomcat/7.0.47
Le code source est très simple.
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"
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">
<servlet>
<servlet-name>loginDispacher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>loginDispacher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
loginDispacher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:component-scan base-package="com.sandeep.controller" />
<!-- View resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
hello.jsp
<%@ page language="Java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://Java.Sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Hello Spring MVC</title>
</head>
<body>
<h2>${message}</h2>
</body>
</html>
HelloController.Java
package com.sandeep.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/hello")
public class HelloController {
@RequestMapping(method=RequestMethod.GET)
public String printHello(ModelMap model){
System.out.println("From controller");
model.addAttribute("message", "Hellow Spring MVC Framework!");
return "hello";
}
}
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.sandeep</groupId>
<artifactId>logindemo</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>logindemo Maven Webapp</name>
<url>http://maven.Apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>com.Oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
<build>
<finalName>logindemo</finalName>
</build>
</project>
Essayez de changer votre version du framework de printemps dans pom.xml en 4.1.5. Ajoutez simplement ceci avant vos dépendances
<properties>
<spring.version>4.1.5.RELEASE</spring.version>
</properties>
Ajoutez ce code dans votre web.xml
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/loginDispacher-servlet.xml</param-value>
</init-param>
Et ce code de ligne dans votre loginDispacher-servlet.
<context:annotation-config />
Dans les exemples de partage suivants avec spring mvc: link
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://Java.Sun.com/xml/ns/javaee"
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">
Les fichiers web.xml et applicationContext.xml xsd doivent être identiques. S'il vous plaît changer une fois.