From the filters project which builds a jar to be shared, provide a class which can be scanned by Spring to create the beans with a well defined name. For example:
package com.me.common.interceptors;
public class InterceptorConfig {
public static final String INTERCEPTOR_BEAN_1 = "comMeCommonInterceptorsInterceptor1";
public static final String INTERCEPTOR_BEAN_2 = "comMeCommonInterceptorsInterceptor2";
@Bean(name = INTERCEPTOR_BEAN_1)
public HandlerInterceptor getInterceptor1() {
return new Interceptor1();
}
@Bean(name = INTERCEPTOR_BEAN_1)
public HandlerInterceptor getInterceptor2() {
return new Interceptor2();
}
}
public class Interceptor1 implements HandlerInterceptor {
// ...
}
public class Interceptor2 implements HandlerInterceptor {
// ...
}
Then configure the app to scan the com.me.common.interceptors package to create the beans. It doesn't matter the code is in a jar.
Within the app, those beans can then be autowired by name, and registered as usual.
@Autowired
@Qualifier(InterceptorConfig .FILTER_BEAN_1)
private HandlerInterceptor interceptor1;
@Autowired
@Qualifier(InterceptorConfig .FILTER_BEAN_2)
private HandlerInterceptor interceptor2;