【问题标题】:Spring mvc resources not loading on first run首次运行时未加载 Spring mvc 资源
【发布时间】:2014-06-05 09:13:01
【问题描述】:

我正在开发一个 Spring Web 应用程序。 我已将所有资源文件夹放在 webcontent 文件夹中,并在我的 dispatcher.xml

中进行了配置
 <mvc:resources location="/asset/" mapping="/asset/**" />

我已将我的启动页面配置如下

<mvc:view-controller path="/" view-name="Framework/start"/>

我的应用程序运行良好,所有资源也在加载,但不是在第一次运行时。意味着当我在 tomcat7 上部署我的应用程序并第一次点击 url 时,css 没有加载,我映射到控制器的 href 也不起作用,但是一旦我登录并注销,一切正常。

【问题讨论】:

    标签: css jakarta-ee tomcat spring-mvc


    【解决方案1】:

    经过大量努力,我得出结论,问题不在于资源路径,而在于拦截器。由于对资源的请求,我添加的身份验证拦截器被多次调用,并且由于在此之前没有创建会话,因此它返回 false。 因此,我通过以下方式从拦截器中排除对资源文件夹的任何调用 -

    <mvc:interceptors>
            <mvc:interceptor>
                    <mvc:mapping path="/**"/>
                    <mvc:exclude-mapping path="/asset/**"/>         
                <bean class="com.model.AuthenticationInterceptor" />
            </mvc:interceptor>
    </mvc:interceptors>
    

    mvc:exclude-mapping 也是从 spring 3.2 开始添加的,所以需要添加架构“http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd

    【讨论】:

      猜你喜欢
      • 2019-01-31
      • 2015-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-27
      相关资源
      最近更新 更多