dimanche 12 avril 2015

Spring error: No mapping found for HTTP request with URI [/project/] in DispatcherServlet with name 'appServlet'


Vote count:

0




After setting up the default security page with Spring security (in memory), I receive the following error:



No mapping found for HTTP request with URI [/myproject/] in DispatcherServlet with name 'appServlet'


I looked into other posts who have the same problem and tried every possible solution that was mentioned. When I add /myproject/ as an url pattern, I don't receive the error but I can not see my page: HTTP Status 404 -. However, when just putting / I get: HTTP Status 404 - /myproject/


Web.xml



<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://ift.tt/nSRXKP"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/nSRXKP 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>

<!-- 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>


servlet-context.xml



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU" xmlns:context="http://ift.tt/GArMu7"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://ift.tt/1jdM0fE"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://ift.tt/GArMu6 http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://ift.tt/GArMu7 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
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xs">

<mvc:annotation-driven />
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->
<context:annotation-config />

<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
<mvc:resources mapping="/resources/**" location="/resources/" />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>


</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU" xmlns:context="http://ift.tt/GArMu7"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://ift.tt/1jdM0fE"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://ift.tt/GArMu6 http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://ift.tt/GArMu7 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
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xs">

<mvc:annotation-driven />
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->
<context:annotation-config />

<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
<mvc:resources mapping="/resources/**" location="/resources/" />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>


</beans>


root-context.xml



<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU" xmlns:context="http://ift.tt/GArMu7"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://ift.tt/1jdM0fE"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://ift.tt/GArMu6 http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://ift.tt/GArMu7 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
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xs">


<context:component-scan base-package="controller" />
<context:component-scan base-package="model" />
<context:component-scan base-package="security" />
</beans>


Controller example:



@RequestMapping(value="/",method = RequestMethod.GET)
public String home(Locale locale, Model model) {
return "home";
}


asked 53 secs ago







Spring error: No mapping found for HTTP request with URI [/project/] in DispatcherServlet with name 'appServlet'

Aucun commentaire:

Enregistrer un commentaire