No mapping was found for the HTTP request with the URI [/ myappname /] in DispatcherServlet named 'appServlet'

I got a No mapping found for HTTP request with URI [/myappname/] in DispatcherServlet with name 'appServlet' when I ran my project on JBoss. This problem occurred after solving another problem described here: "No session for the current thread" after changing the session access method

Before everything worked fine. I use Apache Tiles 2. I read a few similar questions, but I can’t find a working solution.

This is my DispatcherServlet Context file without a Hibernate configuration:

 <?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 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 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- DispatcherServlet Context: defines this servlet request-processing infrastructure --> <!-- Enables the Spring MVC @Controller programming model --> <tx:annotation-driven /> <context:annotation-config /> <context:component-scan base-package="finances.webapp" /> <!-- Handles HTTP GET requests for resources by efficiently serving up static resources in the ${webappRoot}/resources directory --> <resources mapping="/resources/**" location="/resources/" /> <beans:bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"> <beans:property name="definitions"> <beans:list> <beans:value>/WEB-INF/tiles-definitions.xml</beans:value> </beans:list> </beans:property> </beans:bean> <beans:bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <beans:property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" /> </beans:bean> 

My web.xml whole file:

 <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- The definition of the Root Spring Container shared by all Servlets and Filters --> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring/root-context.xml </param-value> </context-param> <!-- Creates the Spring Container shared by all Servlets and Filters --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class> </listener> <!-- Processes application requests --> <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app> 

And this is my IndexController :

 @Controller public class IndexController { @RequestMapping(value = "/", method = RequestMethod.GET) public String index(Model model, Principal principal) { return "index"; } } 

What is wrong with my configuration at the moment?

+1
source share
5 answers

I think you are missing the <mvc:annotation-driven/> , which is required to read @Controller and @RequestMapping . You can read here here and here .

+10
source

Solutio should store annotation-driven tags in the DispatcherServlet Context file, as here:

 <annotation-driven /> <tx:annotation-driven /> 

I did not find such a solution, so I'm going to leave it here.

0
source

Do it in spring servlet.xml file

 xmlns:mvc="http://www.springframework.org/schema/mvc xmlns:tx="http://www.springframework.org/schema/tx" 

and

 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd 

and

 <mvc:annotation-driven /> <tx:annotation-driven /> 

In the controller class use

  @Controller public class IndexController {..} 

and it works!

0
source

I came across the same exception and tried all of the above solutions, but nothing helped but I realized that the problem was that the class was not created in the folder of the target class, and this was due to the incorrect structure of the Maven project, which did not lead to compiling a Java controller class.

Check if you have the structure below, and then if the class is generated in the target->class folder, then use only the suggestions above.

 Project src main java resources test java resources 
0
source

Make sure your .java file is in the src / main / java directory instead of src / main / resources

0
source

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


All Articles