当前位置: 首页 > 知识库问答 >
问题:

将Spring从3.0.5升级到3.2.18-无法访问图像、CSS和JS等资源

范轶
2023-03-14

我是Spring的新手,开始从3.0.5升级到3.2.18,我尝试过修改版本,将工件ID更改为新版本(例如.springframework.core改为spring-core,等等)并在声明中将XSD版本从3.0更新到3.2。我在applicationcontext-security.xml中遇到了一个关于intercept-url的问题

<http auto-config="false" entry-point-ref="authenticationProcessingFilterEntryPoint" use-expressions="true">
<custom-filter position="FORM_LOGIN_FILTER" ref="authenticationProcessingFilter"/>
<custom-filter position="LAST" ref="loadUserContextFilter"/>
<logout logout-url="/static/j_spring_security_logout" logout-success-url="/login" />

<!-- Configure these elements to secure URIs in your application -->
....
...
..

<intercept-url pattern="/admin/campus/buildings/new" access="hasAnyRole('ROLE_RES.APP.CAMPUS.ADMIN_DEV','ROLE_RES.APP.CAMPUS.ADMIN_FULL')"/>
<intercept-url pattern="/admin/campus/buildings/*/sitesofservice/new" access="hasAnyRole('ROLE_RES.APP.CAMPUS.ADMIN_DEV','ROLE_RES.APP.CAMPUS.ADMIN_FULL')"/>
.....

<intercept-url pattern="/admin/**" access="hasAnyRole('ROLE_RES.APP.CAMPUS.ADMIN_FULL','ROLE_RES.APP.CAMPUS.ADMIN_DEV','ROLE_RES.APP.CAMPUS.ADMIN_DIFF')"/>
<intercept-url pattern="/batch/**" access="hasRole('ROLE_RES.APP.CAMPUS.ADMIN_BATCH')"/>
<intercept-url pattern="/resources/**" filters="none" access="permitAll" />
<intercept-url pattern="/static/**" access="permitAll" />
<intercept-url pattern="/**" access="permitAll" />

在上述文件中, 应用程序抛出以下异常。

Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: The use of "filters='none'" is no longer supported. Please define a separate  element for the pattern you want to exclude and use the attribute "security='none'".

我尝试了不同的方法,删除了filters=“none”,并创建了一个新的http属性security=none,但没有一个奏效。

我参考了下面的选项https://www.baeldung.com/security-none-filters-none-access-permitall#security-none并添加了一个新的http元素,但仍然没有成功。

经过上述更改后,文件如下所示

<http pattern="/resources/**" security="none"/>
<http auto-config="false" entry-point-ref="authenticationProcessingFilterEntryPoint" use-expressions="true">
   ...
   ...

应用程序正在成功地构建和部署,但映像、CSS和JS没有加载。日志中没有任何错误(我正在通过创建一个新的本地tomcat服务器来使用IntelliJ来部署和测试应用程序)

感谢任何帮助!

共有1个答案

范建华
2023-03-14

我看到的是,在XML spring配置文件中,您编写了 ,但在显示的图像中,css和js位于stylesjs下,因此我尝试使用以下XML配置:

<http pattern="/styles/**" security="none"/>
<http pattern="/js/**" security="none"/>

否则,您应该将JS和CSS移动到一个名为resources的文件夹下,但这意味着要修改您用来调用这些资源的每个JSP或任何前端技术;影响会更大,但也许,解决方案会更干净

 类似资料:
  • 在我当前的项目中,我们使用的是Spring 3.0.5(core、aop、beans、web、webmvc等)。然而,我们希望使用“Spring Security SAML Extension 1.0.0 RC3”来构建一个服务提供商,该服务提供商已经过Spring 3.1.2、Spring Security 3.1.2和OpenSAML 2.5.3的全面测试。 从Spring 3.0.5升级到S

  • 我想知道是否有人有只通过servlet访问网站资源的解决方案。我的所有资源都在WEB-INF下。换句话说,我不希望用户直接访问我的任何资源。

  • 系统信息: 操作系统:Linux/amd64/3.2.0-4-amd64 Java版本:1.7.021-B11 版本:4.5.2 数据库:MySQL 5.5.41-0+Wheezy1 数据库:URL jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterencoding=utf8&rewriteBatchedStatements=tr

  • 问题内容: 我将servlet转发到JSP时,我在加载CSS和图像以及创建指向其他页面的链接时遇到了麻烦。具体而言,当我把我的给index.jsp的CSS被加载并正在显示我的图片。但是,如果我把我的给HomeServlet其控制推进到index.jsp,CSS中没有被应用,并且不显示我的图片。 我的CSS文件在中web/styles/default.css。 我的图像在web/images/。 我

  • 我正在使用科尔多瓦3.4。当我捕捉图像并设置它时,它工作正常,但当我试图从图库中访问图像时,我得到了url 我的图像标签中出现了图像加载错误。我知道这是一个已知的错误,我已经参考了堆栈问题,例如使用PhoneGap相机插件从Android 4.4(KitKat)的图库中选择时无法加载图像 我不能使用提到的URI手动设置的粗糙方法,如content://media/external/images/m

  • 我不确定这些静态资源是如何加载的,但是在我添加了一个新的控制器映射后,我没有在日志中找到静态资源警告消息的映射。 GET/testproject/org/css/style没有映射。css 让我先解释一下我的项目配置,以便更容易理解问题。 所有JSP位置(视图具有不同的文件夹,用于为不同的模块分隔JSP) 静态资源定位 应用性质 在application.properties添加最后一个配置后,现