Reputation: 295
I am creating a Spring4 MVC application using maven taking "maven-archetype-webapp" as artifactId and adding dependencies "Spring-core","spring-web","Spring-mvc" below is the "web.xml" & "HelloWeb-servlet.xml"
web.xml
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>HelloWeb</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
HelloWeb-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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<context:component-scan base-package="com.zap.pm.*" />
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
and my controller class is as bellow
package com.zap.pm;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HelloController{
@RequestMapping( value="/test")
public String printHello() {
ModelAndView model=new ModelAndView();
model.addAttribute("message", "Hello Spring MVC Framework!");
return "hello";
}
}
I have placed the hello.jsp inside the "/WEB-INF/jsp/" but when accessing the request "http://localhost:8080/webappspring/test.html" it is giving the following error
Oct 12, 2015 7:10:13 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/webappspring/test.html] in DispatcherServlet with name 'HelloWeb'
I have visited the slimier question here but none is solving my problem.
Upvotes: 1
Views: 1431
Reputation: 120
Please check folder structure of your application , i have faced same issue , mine controller was in src/main/resources folder instead of src/main/java.
Upvotes: 2
Reputation: 252
Change your context:component-scan base-package path to be this, you don't need an asterisk:
<context:component-scan base-package="com.zap.pm" />
Upvotes: 2