i tried following code run sample spring rest application tomcat7. works properly, not recognize hellocontroller. debugger not able reach hellocontroller. http://localhost:8080/sample/welcome throws 404 error.
127.0.0.1 - - - 25/09/2015:23:21:27 +0530 "get / http/1.1" 404 - 127.0.0.1 - - - 25/09/2015:23:21:28 +0530 "get /sample/ http/1.1" 200 - 127.0.0.1 - - - 25/09/2015:23:21:34 +0530 "get /sample/welcome http/1.1" 404 -
hellocontroller.java
package com.mkyong.web.controller; @controller public class hellocontroller { @requestmapping(value = { "/", "/welcome**" }, method = requestmethod.get) public modelandview welcomepage() { modelandview model = new modelandview(); model.addobject("title", "spring security hello world"); model.addobject("message", "this welcome page!"); model.setviewname("hello"); return model; } @requestmapping(value = "/admin**", method = requestmethod.get) public modelandview adminpage() { modelandview model = new modelandview(); model.addobject("title", "spring security hello world"); model.addobject("message", "this protected page!"); model.setviewname("admin"); return model; } }
web.xml
<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>sample</display-name> <display-name>spring mvc application</display-name> <!-- spring mvc --> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <listener> <listener-class>org.springframework.web.context.contextloaderlistener </listener-class> </listener> <listener> <listener-class>org.springframework.security.web.session.httpsessioneventpublisher </listener-class> </listener> <!-- spring security --> <filter> <filter-name>springsecurityfilterchain</filter-name> <filter-class>org.springframework.web.filter.delegatingfilterproxy </filter-class> </filter> <filter-mapping> <filter-name>springsecurityfilterchain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>
spring-security.xml
<beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="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-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <context:annotation-config /> <context:spring-configured /> <mvc:annotation-driven /> <mvc:default-servlet-handler/> <http auto-config="true"> <intercept-url pattern="/admin**" access="role_user" /> </http> <authentication-manager> <authentication-provider> <user-service> <user name="k" password="123" authorities="role_user" /> </user-service> </authentication-provider> </authentication-manager> </beans:beans>
here mvc-dispatcher-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" xsi:schemalocation=" 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"> <context:component-scan base-package="com.mkyong.web.controller" /> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix"> <value>/web-inf/pages/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> </beans>
you seems missing spring-servlet-config
file , content in spring-security
file. create file mvc-dispatcher-servlet.xml
in web-inf
folder , add following it:
<beans:beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> <context:annotation-config /> <context:spring-configured /> <mvc:annotation-driven /> <mvc:default-servlet-handler/> </beans:beans>
you remove moved content security configuration file.
Comments
Post a Comment