Ich versuche, dieses Beispiel funktioniert: http://www.tutorialspoint.com/spring/spring_mvc_hello_world_example.htmorg.springframework.web.servlet.PageNotFound noHandlerFound in Eclipse
Eclipse Version mit: Mars.2 Veröffentlichung (4.5.2), Java 8, Maven und Kater 8 (innerhalb der Eclipse) auf ubuntu 15.10.
Mein Projekt ist wie folgt organisiert:
webapp (maven parent pom)
webapp-module (maven war sub module)
-> src
-> main
-> java
-> com
-> samples
-> HelloController.java
-> webapp
-> WEB-INF
-> jsp
-> hello.jsp
-> web.xml
-> webapp-module-servlet.xml
Wo:
web.xml
<web-app id="WebApp_ID" 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">
<display-name>Spring MVC Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/webapp-module-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>webapp-module</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>webapp-module</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
</web-app>
Webapp-Modul-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:annotation-config/>
<context:component-scan base-package="com.samples.*" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
hello.jsp
<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h2>${message}</h2>
</body>
</html>
HelloController.java
package com.samples;
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) {
model.addAttribute("message", "Hello Spring MVC Framework!");
return "hello";
}
}
Aber wenn ich es in Eclipse laufen erhalte ich:
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
May 01, 2016 9:35:45 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
May 01, 2016 9:35:45 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
May 01, 2016 9:35:45 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
May 01, 2016 9:35:45 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Sun May 01 21:35:45 CEST 2016]; root of context hierarchy
May 01, 2016 9:35:45 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/webapp-module-servlet.xml]
May 01, 2016 9:35:45 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 657 ms
May 01, 2016 9:35:45 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'webapp-module'
May 01, 2016 9:35:45 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'webapp-module': initialization started
May 01, 2016 9:35:45 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'webapp-module-servlet': startup date [Sun May 01 21:35:45 CEST 2016]; parent: Root WebApplicationContext
May 01, 2016 9:35:45 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/webapp-module-servlet.xml]
May 01, 2016 9:35:46 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'webapp-module': initialization completed in 313 ms
May 01, 2016 9:35:46 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
May 01, 2016 9:35:46 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
May 01, 2016 9:35:46 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2241 ms
May 01, 2016 9:35:46 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/webapp-module/] in DispatcherServlet with name 'webapp-module'
May 01, 2016 9:35:53 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/webapp-module/hello] in DispatcherServlet with name 'webapp-module'
Ich verwende:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
Es gibt einen gibt viele Beiträge im Netz über diese Empfehlung unterschiedliche xml oneliners hier und dort hinzuzufügen. Ich habe die meisten von ihnen versucht, aber immer noch den gleichen Fehler.
Irgendwelche Vorschläge?
Wo ist Ihr Hello Klasse? – xsalefter
Es hat nur vergessen, es zu meinem Beitrag hinzuzufügen. – u123
Versuchen Sie, 'http: // localhost: 8080/webapp-modul/hallo/printHello.jsp' zu öffnen und stellen Sie sicher, dass der Name und Pfad der jsp-Datei korrekt ist:'/WEB-INF/jsp/hello.jsp' – xsalefter