我有2個問題在這裏:HTTP 404:春季安全網址過濾器和調度服務器URL映射之間的衝突
月1日:我得到一個HTTP 404。我認爲這是春季安全過濾器URL映射之間的衝突和調度程序servlet映射。我在說,因爲當我從我的
web.xml
中刪除彈簧安全配置時,請求映射過程正常工作。第二:我得到了「臭名昭著」 HTTP 500無法計算表達式「ROLE_ADMIN」
現在怎麼可能對我有問題2如果我擺在首位404?我對此毫不知情。昨天一切都在問題1正常工作,所以我得到了HTTP 500.今天,我不能通過HTTP 404.至少我已經找到了我的配置中的罪魁禍首。
請幫我解決問題1 < - 這是這個問題的主要問題(如果你還有問題2)...下面是我的xml配置文件。
的web.xml
<web-app version="3.0" 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_3_0.xsd">
<!-- For front controller i.e. dispatcher servlet -->
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class> org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/webcontext/DispatcherServlet-context.xml
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- For Spring security -->
<!-- When I remove all items below, my app works fine -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/webcontext/security-context.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<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>
的DispatcherServlet-context.xml的
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="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-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<!-- To enable spring annotations @RequestMapping, @Controller, @Repository, etc... -->
<mvc:annotation-driven />
<!-- To enable @MatrixVariable -->
<mvc:annotation-driven enable-matrix-variables="true"/>
<!-- To set the package where dispatcher servlet looks for controllers
Some other scanning for other purpose may also occur in that package
For instance for @Autowired to look for interfaces-->
<context:component-scan base-package="com.packt.webstore" />
<!-- Sets where ViewResolver looks for views -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- For static resources. Example : CSS, JS, etc... -->
<mvc:resources mapping="/resources/**" location="/ressources/theme1/" />
<!-- For externalizing messages -->
<bean id= "messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages"/>
</bean>
</beans>
安全的context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="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"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<security:http auto-config="true">
<security:intercept-url pattern="/products/add" access="hasRole('ROLE_ADMIN')" />
<security:form-login login-page="/login"
default-target-url="/products/add"
authentication-failure-url="/loginfailed"/>
<security:logout logout-success-url="/logout" />
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="Admin"
password="Admin123"
authorities="ROLE_ADMIN" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
</beans>
正如你可以看到在security-cntext.xml
配置,我試圖通過添加hasRole('ROLE_ADMIN')
建議here
嘗試用'ADMIN'替換'ROLE_ADMIN'。據我所知,它應該自動添加前綴'ROLE_' –
@DmitrySenkovich但是HTTP 404呢?由於HTTP 404 – Bloomberg58
你確定它是正確的位置:'location =「/ ressources/theme1 /」',所以我無法到達將'ROLE_ADMIN'更改爲'ADMIN'的部分。我的意思是兩個'ss'在'ressources' –