我正在开发一个 Spring Web 应用程序。我已将所有资源文件夹放入 网页内容 文件夹并在我的dispatcher.xml中配置它

 <mvc:resources location="/asset/" mapping="/asset/**" />

我的启动页面配置如下

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

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

有帮助吗?

解决方案

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

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

还有一件小鬼的事 mvc:排除映射 添加自 春季 3.2 及以上 所以需要添加架构“http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top