java - Spring MVC 4.1.7 WARNING: No mapping found for HTTP request with URI [/user] in DispatcherServlet -


i trying link annotation defined java controller requestmapping. specifically, localhost:8080/user , localhost:8080/signin

the index page loads fine, that's not due controller. must missing silly. i've been , down stack overflow looking solutions, far nothing has worked.

the popular answers warning seem adding context:component-scan, mvc:annotation-driven, or naming issues. seems have configuration in xml necessary, , some. missing project structure? or url pattern matching? mentioned jstl , adding c:tags urls, didn't work either.

i'm trying run latest, maybe there's issue? had trouble setting environment work webapp 3.1. of configuration happened automatically spring sts tool.

  • java 8
  • tomcat 8
  • web app 3.1
  • maven 4.0
  • sts 3.7.0

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/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>group</groupid> <artifactid>artifact</artifactid> <version>0.0.1-snapshot</version> <packaging>war</packaging> <name>appname</name> <description>app desc</description>  <!-- custom properties --> <properties>     <spring.version>4.1.7.release</spring.version> </properties>  <dependencies>     <!-- spring -->     <dependency>         <groupid>org.springframework</groupid>         <artifactid>spring-core</artifactid>         <version>${spring.version}</version>     </dependency>     <dependency>         <groupid>org.springframework</groupid>         <artifactid>spring-web</artifactid>         <version>${spring.version}</version>     </dependency>     <dependency>         <groupid>org.springframework</groupid>         <artifactid>spring-webmvc</artifactid>         <version>${spring.version}</version>     </dependency>      <!-- j2ee -->     <dependency>         <groupid>jstl</groupid>         <artifactid>jstl</artifactid>         <version>1.2</version>     </dependency>      <!-- logging -->     <dependency>         <groupid>commons-logging</groupid>         <artifactid>commons-logging</artifactid>         <version>1.2</version>     </dependency>      <!-- testing -->     <dependency>         <groupid>junit</groupid>         <artifactid>junit</artifactid>         <version>3.8.1</version>         <scope>test</scope>     </dependency> </dependencies>  <build>     <finalname>instagrampue</finalname>     <sourcedirectory>src/main/java</sourcedirectory>     <plugins>         <plugin>             <artifactid>maven-compiler-plugin</artifactid>             <version>3.3</version>             <configuration>                 <source>1.8</source>                 <target>1.8</target>             </configuration>         </plugin>         <plugin>             <artifactid>maven-war-plugin</artifactid>             <version>2.6</version>             <configuration>                 <warsourcedirectory>webapp</warsourcedirectory>                 <failonmissingwebxml>false</failonmissingwebxml>             </configuration>         </plugin>         <plugin>             <groupid>org.apache.tomcat.maven</groupid>             <artifactid>tomcat7-maven-plugin</artifactid>             <version>2.2</version>         </plugin>     </plugins> </build> </project> 

web.xml

<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="igpue" version="3.1">  <!-- app config --> <display-name>app display name</display-name> <description>app desc</description>  <welcome-file-list>     <welcome-file>index.jsp</welcome-file> </welcome-file-list>  <!-- app context --> <listener>     <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener>  <context-param>     <param-name>contextconfiglocation</param-name>     <param-value>/web-inf/spring/app-context.xml</param-value> </context-param>  <!-- servlet config --> <servlet>     <servlet-name>mvc-dispatcher</servlet-name>     <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>     <init-param>         <param-name>contextconfiglocation</param-name>         <param-value>/web-inf/spring/mvc-dispatcher-servlet.xml</param-value>     </init-param>     <load-on-startup>1</load-on-startup> </servlet>  <servlet-mapping>     <servlet-name>mvc-dispatcher</servlet-name>     <url-pattern>/</url-pattern>     <url-pattern>/signin</url-pattern>     <url-pattern>/user</url-pattern> </servlet-mapping>  <servlet-mapping>     <servlet-name>default</servlet-name>     <url-pattern>*.css</url-pattern> </servlet-mapping> <servlet-mapping>     <servlet-name>default</servlet-name>     <url-pattern>*.js</url-pattern> </servlet-mapping> <servlet-mapping>     <servlet-name>default</servlet-name>     <url-pattern>*.gif</url-pattern> </servlet-mapping> <servlet-mapping>     <servlet-name>default</servlet-name>     <url-pattern>*.jpg</url-pattern> </servlet-mapping> <servlet-mapping>     <servlet-name>default</servlet-name>     <url-pattern>*.png</url-pattern> </servlet-mapping> <servlet-mapping>     <servlet-name>default</servlet-name>     <url-pattern>*.txt</url-pattern> </servlet-mapping> </web-app> 

mvc-dispatcher-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     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-4.1.xsd                        http://www.springframework.org/schema/context                         http://www.springframework.org/schema/context/spring-context-4.1.xsd                        http://www.springframework.org/schema/mvc                        http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">   <!-- mvc config --> <mvc:annotation-driven /> <mvc:resources location="/resources/" mapping="/resources/**" />  <!-- scan controller --> <context:component-scan base-package="abnd.igpue.controller" />  <!-- bean config --> <bean id="viewresolver" class="org.springframework.web.servlet.view.internalresourceviewresolver">     <property name="prefix" value="/web-inf/jsp/" />     <property name="suffix" value=".jsp" /> </bean>  </beans> 

index.jsp

<%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!doctype html> <html> <head>     <title>title</title>     <meta charset="utf-8" />     <meta http-equiv="content-type" content="text/html" />     <link href="<c:url value='/resources/css/style.css' />" rel="stylehseet" type="text/css" /> </head> <body>     <!-- html -->     <div id="page">         <div id="header">             <div id="title"><span>title</span></div>         </div>         <div id="content">             <div id="signin">                 <c:url value="/signin" var="signinlink" />                 <div id="signinlink"><a href="${signinlink}">sign in instagram</a></div>                 <c:url value="/user" var="userlink" />                 <div id="userpage"><a href="${userlink}">user page</a></div>             </div>         </div>     </div>     <!-- js -->     <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script> </body> </html> 

user.java

package abnd.igpue.controller;  import org.springframework.stereotype.controller; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.servlet.modelandview;  @controller  public class user {  @requestmapping(value = "/signin") public string signin() {        // if signin successful redirect user page      return "redirect:user"; }  @requestmapping(value = "/user")   public modelandview userhome() {     modelandview mav = new modelandview("/jsp/user.jsp");     mav.setviewname("user");      string message = "<br><div>"             + "<h1>hello world</h1></div><br><br>";      mav.addobject("message", message);      return mav; } } 

i have gotten working. scrapped code had, , rebuilt ground up. found few issues in last project between these 2 stack overflow posts (below), after getting new project work, not successfuly update code positing originally. there must silly missing.

resources

a post here details how using <mvc:resources .../> in spring 3 causes other views stop working post here details how add css in spring mvc

i have uploaded starter spring web mvc project github!

if interested, here ya go. can download , import maven project. https://github.com/boryshn/springmvcskeleton


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -