我已经创建了一个springmvc项目,它有两个控制器、一些dao、dto和jsp文件。我删除了 @RequestMapping(value = "/login", method = RequestMethod.GET)
在我的控制器上检查spring的安全性是否正常。
但是,它根本不起作用,总是显示404错误。如果错误代码是403,那么我可以修复context-security.xml的设置。但我不知道我错过了什么。
不管怎样,我只是将pom.xml设置为像这样注入依赖关系(我的spring框架是3.1.1,所以spring安全版本也是3.1.1)
<java-version>1.6</java-version>
<org.springframework-version>3.1.1.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
</properties>
<dependencies>
<!-- Spring-Security -->
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Spring-Security-Taglibs -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>${org.springframework-version}</version>
</dependency>
我在appservlet文件夹中创建了context-security.xml。
<?xml version="1.0" encoding="UTF-8"?>
<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.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/**" access="ROLE_USER" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="user" password="1234" authorities="ROLE_USER"/>
<user name="guest" password="guest" authorities="ROLE_GUEST"/>
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
我给web.xml添加了一些代码
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml
/WEB-INF/spring/context-security.xml
</param-value>
</context-param>
<!-- Spring Security Filter -->
<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>
我查了一些例子。他们可以看到spring安全登录页,而不需要额外的类,这些类具有configuaraion注解或enablewebsecurity。但我的已经三个小时没工作了。
另外,我生成了一个新的mvc项目并复制了三个xml代码。仅homecontroller和home.jsp。因此,我可以从项目中看到完全相同的错误。 The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
然后我就搬走了 <intercept-url pattern="/**" access="ROLE_USER" />
==>失败==>失败==>失败==>holo是我的项目名称。安威失败
但根本没用。这些xml有什么错误吗?或者根本不起作用?
暂无答案!
目前还没有任何答案,快来回答吧!