Matt
Matt

Reputation: 2815

Spring MVC Sharing same interceptor for multiple paths

I am using a WebContentInterceptor to enable long lived cache of static resources. We have them under 3 different paths though, css, js, and images.

Is there a way to share the interceptor bean between multiple mappings without putting them all under a shared path?

Upvotes: 5

Views: 8516

Answers (2)

smp7d
smp7d

Reputation: 5032

I'd need more information to confirm that the setup is how I presume; but, have you tried...

<mvc:interceptors>
    <mvc:interceptor>
        <mvc:mapping path="/site/*" />
        <mvc:mapping path="/add/*" />
        <mvc:mapping path="/edit" />
        <bean class="com.test.MyInterceptor" />
    </mvc:interceptor>
</mvc:interceptors>

Upvotes: 10

The above answer doesn't work. And I could not find anything such as paths But found a workaround.

<mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/notes/**" />            
            <bean class="com.bridgelabz.todoApp.interceptor.LoginInterceptor" />
        </mvc:interceptor>

        <mvc:interceptor>
            <mvc:mapping path="/user/getUserById" />            
            <bean class="com.bridgelabz.todoApp.interceptor.LoginInterceptor" />
        </mvc:interceptor>

Upvotes: 0

Related Questions