Java 使用集成的Spring安全性访问Spring 3 MVC应用程序中的静态内容
我已经通过Spring工具套件模板创建了Spring3MVC项目,并且在那里集成了Spring安全性。。除了访问静态内容之外,一切都正常 当我只创建MVC应用程序,将静态内容放在Java 使用集成的Spring安全性访问Spring 3 MVC应用程序中的静态内容,java,spring,spring-mvc,spring-security,Java,Spring,Spring Mvc,Spring Security,我已经通过Spring工具套件模板创建了Spring3MVC项目,并且在那里集成了Spring安全性。。除了访问静态内容之外,一切都正常 当我只创建MVC应用程序,将静态内容放在/src/webapp/WEB-INF/resources/中,并将放在我的applicationContext.xml中时,它工作得很好…但是我不能安全地将此代码添加到我的applicationContext.xml中…代码甚至没有编译..知道如何写入我的web.xml以使其工作吗 我的applicationConte
/src/webapp/WEB-INF/resources/
中,并将
放在我的applicationContext.xml
中时,它工作得很好…但是我不能安全地将此代码添加到我的applicationContext.xml
中…代码甚至没有编译..知道如何写入我的web.xml以使其工作吗
我的applicationContext.xml
文件如下所示:
src/main/java
src/main/resources
src/main/webapp
src/main/webapp/WEB-INF
src/main/webapp/WEB-INF/jsps
src/main/webapp/css
奇怪的是,当使用上面的代码时,mapping view controller可以正常工作,但是当我使用它时,我得到了这个错误前缀mvc:resources-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>
解决方案的结构:
代码应该在应用程序上下文定义(applicationContext.xml)中,并且位置相对于部署根目录:
<mvc:resources location="/resources/" mapping="/resources/**"/>
然后
xsi:schemaLocation = http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
我想可能有点混乱,正常的WDdirectory结构是这样的:
src/main/java
src/main/resources
src/main/webapp
src/main/webapp/WEB-INF
src/main/webapp/WEB-INF/jsps
src/main/webapp/css
css目录只是一个例子,我有javascipt,还有图像目录,有些人更喜欢一个叫做“静态资产”的目录。但称之为资源是相当混乱的。src/main/resource/目录实际上包含整个项目的配置文件(我将appContext.xml和log.properties文件放在其中),它在部署时被复制到WEB-INF,不应用于映射静态资源。
例如,在我的示例中,数据实际上会这样映射:
<mvc:resources location="/css/" mapping="/css/**"/>
该代码不应该出现在web.xml
中,我认为,它应该出现在您的servlet上下文中,我不能,因为我已经尝试过了,但它不起作用。我得到错误:前缀mvc:resources未绑定
现在我意识到,添加
后,我无法使用控制器访问页面。我收到警告:WARN:org.springframework.web.servlet.PageNotFound-在名为“mvc dispatcher”的DispatcherServlet中找不到URI为[/fit/]的HTTP请求的映射。
@Dworza您的资源目录应该向上移动一个。。。部署时的根目录是webapp目录。我认为,由于安全性,它无法工作:-/因为在其他项目中,这非常有效…@Dworza也需要在配置中,在资源映射之前