Обновлено
Мой вопрос в том, как инициализировать изолированное веб-приложение webmvc spring в spring. Изолированное веб-приложение должно:
- Не следует инициализировать себя в классе приложения. Мы хотим сделать это в стартовом помпе с помощью автоматической настройки. У нас есть несколько таких веб-приложений, и нам нужна гибкость автоматической настройки.
- Уметь настраивать себя с помощью таких интерфейсов, как:
WebSecurityConfigurer
(у нас есть несколько веб-приложений, каждый из них безопасность по-своему) иEmbeddedServletContainerCustomizer
(to установить путь к контуру сервлета). - Нам нужно изолировать beans от определенных веб-приложений и не хотеть, чтобы они входили в родительский контекст.
Прогресс
Ниже приведен список классов конфигурации, приведенных в моих метафайлах META-INF/ spring.
Следующая стратегия не приводит к функционированию сервлета web-mvc. Контекстный путь не задан, и ни одна из них не настроена по безопасности. Моя догадка заключается в том, что мне нужно включить определенный webmvc beans, который обрабатывает контекст и автоматически настраивается на основе того, что присутствует beans, подобно тому, как я получил конфигурацию заполнителя свойств на основе загрузки, включив PropertySourcesPlaceholderConfigurer.class
.
@Configuration
@AutoConfigureAfter(DaoServicesConfiguration.class)
public class MyServletConfiguration {
@Autowired
ApplicationContext parentApplicationContext;
@Bean
public ServletRegistrationBean myApi() {
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.setParent(parentApplicationContext);
applicationContext.register(PropertySourcesPlaceholderConfigurer.class);
// a few more classes registered. These classes cannot be added to
// the parent application context.
// includes implementations of
// WebSecurityConfigurerAdapter
// EmbeddedServletContainerCustomizer
applicationContext.scan(
// a few packages
);
DispatcherServlet ds = new DispatcherServlet();
ds.setApplicationContext(applicationContext);
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(ds, true, "/my_api/*");
servletRegistrationBean.setName("my_api");
servletRegistrationBean.setLoadOnStartup(1);
return servletRegistrationBean;
}
}