0
因为我正在学习弹簧安全,我正在尝试我的第一个例子,它给我404错误。请在下面找到春季安全没有加载页面给404 404
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
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/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<security:http auto-config="true">
<security:intercept-url pattern="/hello"
access="ROLE_SCARVAREZ_MEMBER" />
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user authorities="ROLE_SCARVAREZ_MEMBER"
name="car" password="scarvarez" />
<security:user authorities="ROLE_SCARVAREZ_MEMBER"
name="mon" password="scarvarez" />
<security:user authorities="ROLE_SCARVAREZ_MEMBER"
name="bea" password="scarvarez" />
<security:user authorities="ROLE_SCARVAREZ_MEMBER"
name="andr" password="scarvarez" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
</beans>
安全配置文件后来我有一个servlet如下
package com.security.test;
import java.io.IOException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(urlPatterns = { "/hello" })
public class HelloWorldServlet extends HttpServlet {
private static final long serialVersionUID = 2218168052197231866L;
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) {
try {
response.getWriter().write("Hello World");
} catch (IOException e) {
e.printStackTrace();
}
}
}
这里的一切,除了当我登录去罚款,而不是世界你好它给了我404没有什么存在在tomcat控制台上。只是想知道这可能是什么问题?
编辑: - 请您使用Spring的安全,你不必使用HttpServlet的,但春找到我web.xml
文件
<web-app>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext-security.xml
</param-value>
</context-param>
<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>
</web-app>
你为什么在Spring中使用'HttpServlet'? – Andremoniy
是我打电话的'/ hello' URL。这是同一个URL调用和登录,成功后,调用Hello World – Nilesh
@Andremoniy:也可以使用'@ Controller',但这会是一个问题吗? – Nilesh