我是新的Spring开发人员。我想用数据库创建注册Spring Security身份验证和授权。我从下面的github vai链接下载源代码:
https://github.com/eugenp/tutorials/tree/master/spring-security-login-and-registration
我将源代码导入eclipse并运行项目之后我访问url如下:
http://localhost:8877/spring-security-login-and-registration/user/registration
显示错误404 - 未找到。请帮帮我!
答案 0 :(得分:0)
在spring security configuration xml文件中使用security:form-login login-page
标记。它会自动将您的应用程序重定向到登录页面。
REMEBER: 在您的控制器中配置这些网址。
<security:http auto-config="true" use-expressions="true">
<security:intercept-url pattern="/login"
access="permitAll" />
<security:intercept-url pattern="/accessDenied"
access="permitAll" />
<security:intercept-url pattern="/loginFail"
access="permitAll" />
<security:intercept-url pattern="/logout"
access="permitAll" />
<security:intercept-url pattern="/resources/**"
access="permitAll" />
<security:intercept-url pattern="/**"
access="hasRole('ROLE_ADMIN')" />
<security:access-denied-handler
error-page="/accessDenied" />
<security:form-login login-page="/login"
default-target-url="/home" always-use-default-target="true"
authentication-failure-url="/loginFail" username-parameter="username"
password-parameter="password" />
<security:logout logout-success-url="/logout" />
</security:http>
这是关于春季安全的最佳reference tutorial,我遇到过。请尝试根据此配置您的应用程序,如果您想要两种配置( JAVA / XML )REFER THIS或MKYONG。
我希望这会有所帮助。