【发布时间】:2013-03-21 17:51:58
【问题描述】:
我通过 Spring Tool Suite 模板创建了 Spring 3 MVC 项目,并在那里集成了 Spring 安全性。除了访问静态内容之外,一切正常。
当我只创建 MVC 应用程序并将我的静态内容放在 /src/webapp/WEB-INF/resources/ 中并将 <resources mapping="/resources/**" location="src/main/webapp/WEB-INF/resources" /> 放入我的 applicationContext.xml 时,它运行良好......但我无法将此代码添加到我的 applicationContext.xml 安全...代码甚至没有编译..知道要写什么到我的 web.xml 来使它工作吗?
我的applicationContext.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:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<context:annotation-config />
<context:component-scan base-package="cz.cvut.fit.genepi.controllers" />
<import resource="classpath:applicationContext-security.xml" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
奇怪的是,当使用上面的代码时,映射视图控制器工作正常,但是当我使用它时,我得到了这个错误The prefix mvc:resources is not bound
<?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:security="http://www.springframework.org/schema/security"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<context:annotation-config />
<context:component-scan base-package="cz.cvut.fit.genepi.controllers" />
<import resource="classpath:applicationContext-security.xml" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:resources mapping="/resources/**" location="/resources/" />
</beans>
解决方案的结构:
【问题讨论】:
-
该代码不应该在
web.xml中,我认为它应该在您的servlet 上下文中
标签: java spring spring-mvc spring-security