Question

I m developing a spring web application . I have put all my resources folder in webcontent folder and configured it in my dispatcher.xml

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

I have configured my startup page as following

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

My application is running fine and all the resources are also loading but not on the first run. Means when I deploy my application on tomcat7 and hit the url for the first time the css are not loaded also my href which is mapped to a controller is also not working but once I am logged in and logout everything works fine.

Was it helpful?

Solution

After lots of effort i concluded that the problem was not with the resource path but the problem was due to the interceptor . The authentication interceptor that i have added was called multiple times due to the request to the resources and as there was no session created till that time it was returning false. Hence i exclude any calls to resources folder from the interceptor in the following way-

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

Also one imp thing mvc:exclude-mapping is added from spring 3.2 onwards so one need add the schema "http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top