Spring MVC - No mapping found for request URI?

I get some problem using spring MVC Here is my web.xml config

<!-- config spring --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/applicationContext.xml, /WEB-INF/classes/xfire-servlet.xml, /WEB-INF/classes/mvc-servlet.xml, classpath:org/codehaus/xfire/spring/xfire.xml </param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <listener> <listener-class> org.springframework.web.util.IntrospectorCleanupListener </listener-class> </listener> <!-- spring mvc --> <servlet> <servlet-name>mvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>mvc</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> 

My controller is watching

 @Controller @RequestMapping("/searchCase.do") public class SearchCaseController { public String getCaseDetailInfo() { return "forward:caseDetail"; } } 

and my mvc configuration

 <!--auto scan annotation --> <context:component-scan base-package="com.thunisoft.shxt.webservice.model.searchCase.logic" /> <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/case" /> <property name="suffix" value=".jsp" /> </bean> 

Then I request the url: http: // {address: port} / {application-name} /searchCase.do, But it cannot find the controller to resolve my request with

  No handler found in getLastModified DispatcherServlet with name 'mvc' processing request for [/{application-name}/searchCase.do] No mapping found for HTTP request with URI [/{application-name}/searchCase.do] in DispatcherServlet with name 'mvc' Successfully completed request 

My spring MVC version is 2.5.6. I am waiting for your questions to help me solve this problem, thanks!

+5
source share
5 answers

Change the controller url pattern as i said below

.do will be automatically added to the entire controller request mapping as you configured in web.xml

 @Controller @RequestMapping("/searchCase") public class SearchCaseController { public String getCaseDetailInfo() { return "forward:caseDetail"; } } 

JSP Code:

 <a href="/searchCase.do">Click</a> 
+3
source

Try adding method level annotation as follows:

 @Controller @RequestMapping("/searchCase") public class SearchCaseController { @RequestMapping(method = RequestMethod.GET) public String getCaseDetailInfo() { return "forward:caseDetail"; } } 

As described in the docs: Matching Requests with @RequestMapping

17.3.2 Matching Requests Using @RequestMapping

You use the @RequestMapping annotation to map URLs such as /appointments to the entire class or specific handler method. Typically, class-level annotation maps a specific request path (or path template) to a form controller, with an additional level of annotation method, narrowing the primary mapping for a particular HTTP method, the request method ("GET", "POST", etc.) or the request parameter HTTP status.

+1
source

What people suggest in the comments is what docs describes

After initializing the DispatcherServlet, Spring MVC looks for a file named [servlet-name] -servlet.xml in the WEB-INF directory of your web application and creates beans there, overriding the definitions of any beans defined with the same name in the global scope.

However, using the configuration

 <init-param> <param-name>namespace</param-name> <param-value>mvc</param-value> </init-param> 

you overdo it, so the DispatherServlet file will look like this

 DEFAULT_CONFIG_LOCATION_PREFIX + getNamespace() + DEFAULT_CONFIG_LOCATION_SUFFIX 

so in your example it will be

 /WEB-INF/mvc.xml 

I see for your comment that you originally had your own name (corresponding to your configuration). Thus, it is either that you did not place it under WEB-INF, or your problems are located elsewhere.

Speaking of this, consider an alternative configuration (clearer in my opinion) based on the contextConfigLocation parameter, for example

 <servlet> <servlet-name>springMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/mvc-servlet.xml</param-value> </context-param> 

Hope this helps

0
source

I am setting up my project on my computer. First, I start the project using maven-jetty-plugin . Then no detection error was found. After many changes, finally I tried maven-tomcat7-plugin , then it worked.

Add tomcat plugin to your pom.xml

  <build> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> </plugin> </plugins> </build> 

Then start the mvn tomcat7:run server

Your controller mapping should be like this:

 @RequestMapping(value="/searchCase", method = RequestMethod.GET) public ModelAndView helloWorld() { 
0
source

I had the same error. After checking everything that I found during the stack overflow, I didn’t understand anything, I realized that I have a controller in the src/main/resources/com/controllers folder, where com.controllers was supposed to be a package.

Creating another src/main/java source folder and moving the com/controllers folder there did the trick. (He found the com/controller folder as a package, whereas in src/main/resources it was considered as a regular directory.)

0
source

Source: https://habr.com/ru/post/1209056/


All Articles