Basically I want to split my application into 2 parts. Each part has it's own security stuff and own @Controller
s. The @Services
should be accessible from both parts.
So I thought, I should get 2 DispatcherServlet
. One listening to /admin/*
and the second listening to everything else ( /
). Each of those will have its own AnnotationConfigWebApplicationContext
so I can have separate component scan for the @Controller
s.
And because Spring Boot provides one DispatcherServlet
listening on /
out of the box, I thought, I can just add a second one:
@Configuration
public class MyConfig {
@Bean(name="myDS")
public DispatcherServlet myDS(ApplicationContext applicationContext) {
AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext();
webContext.setParent(applicationContext);
webContext.register(MyConfig2.class);
// webContext.refresh();
return new DispatcherServlet(webContext);
}
@Bean
public ServletRegistrationBean mySRB(@Qualifier("myDS") DispatcherServlet dispatcherServlet) {
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(dispatcherServlet);
servletRegistrationBean.addUrlMappings("/admin/*");
servletRegistrationBean.setName("adminServlet");
return servletRegistrationBean;
}
}
The MyConfig2
class, only has @Configuration
and @ComponentScan
. Within the same package is a @Controller
.
When starting the application, I can see, that the second servlet mapping is getting registered, but the @Controller
is not. Additionally I can now access all @Controllers
from /
and /admin
.
Any idea how I can get this working?