Tôi đã phát triển ứng dụng Spring và triển khai tích hợp bảo mật mùa xuân cho chức năng Đăng nhập và Đăng xuất trong đó. Tôi đã sử dụng bảo mật Spring với cấu hình xml. Nhưng khi tôi đăng nhập vào hệ thống, nó hiển thị 404 cho tôi. Bảng điều khiển nói với tôi, Không có ánh xạ tìm thấy cho yêu cầu HTTP URI [/ pms/j_spring_security_check] trong DispatcherServlet với tên 'appServlet'Không tìm thấy ánh xạ nào cho yêu cầu HTTP với URI [/ pms/j_spring_security_check] trong DispatcherServlet với tên 'appServlet'
Nhưng tôi không thể hiểu được lỗi. Những gì tôi đã bỏ lỡ?
My web.xml
<?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 -->
<!-- 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>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/spring-security.xml</param-value>
</context-param>
<!-- 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>
</web-app>
My điều khiển phương pháp:
@RequestMapping(value="/login", method = RequestMethod.GET)
public ModelAndView printWelcome() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("message", "Spring security allows you");
modelAndView.setViewName("loginForm");
return modelAndView;
}
My mùa xuân-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"
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">
<http auto-config="true">
<intercept-url pattern="/loginForm"/>
<intercept-url pattern="/" access="ROLE_USER" />
<form-login login-page="/loginForm"
default-target-url="/login" always-use-default-target="true"
authentication-failure-url="/loginForm?login_error=1" />
<logout logout-success-url="/loginForm" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="a2ztechguide" password="123456" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
Và của trang Đăng nhập của tôi:
<body>
<table>
<tr>
<td valign="top"><c:if test="${not empty param.login_error}">
<font color="red"> Invalid user name or password, try again.
<br /> <br />
</font>
</c:if>
<form name="login_form"
action="<c:url value='j_spring_security_check'/>" method="POST">
<div>
<table width="40%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top">
<table border="0" cellspacing="0" cellpadding="4" width="40%">
<tr>
<td colspan="2">Custom Login Form
<hr width="100%" size="1" noshade align="left">
</td>
<td></td>
</tr>
<tr>
<td width="80">Username</td>
<td valign="top" align="left"><input type='text'
id='username' size="30" maxlength="40" name='j_username'
value='<c:if test="${not empty param.login_error}">
<c:out value="${SPRING_SECURITY_LAST_USERNAME}"/>
</c:if>' />
</td>
</tr>
<tr>
<td width="80">Password</td>
<td valign="top" align="left"><input type='password'
name='j_password' size="30" maxlength="30"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form></td>
</tr>
</table>
</body>
Hãy giúp tôi.
Bạn đã khắc phục được sự cố chưa? Tôi đang gặp vấn đề tương tự. – Harry
Có thể trùng lặp [Tại sao Spring MVC phản hồi bằng 404 và báo cáo "Không có ánh xạ nào được tìm thấy cho yêu cầu HTTP với URI \ [... \] trong DispatcherServlet"?] (Http://stackoverflow.com/questions/41577234/why -does-spring-mvc-respond-with-a-404-and-report-no-mapping-found-cho-http-req) – BalusC