如何在 war packaging 应用程序中激活webflux
安全性。我使用的是Spring 5内置AbstractAnnotationConfigDispatcherHandlerInitializer
,但它不起作用。
public class AppIntializer extends AbstractAnnotationConfigDispatcherHandlerInitializer {
@Override
protected Class<?>[] getConfigClasses() {
return new Class[]{
WebConfig.class,
SecurityConfig.class
};
}
}
但似乎没有启用Spring Security WebFilter。 Spring Security 5不包含特定于Reactor的WebApplicationInitializer
来激活Spring安全过滤器链。
Stack:Spring Security 5.0.0.M4
答案 0 :(得分:0)
您应该可以使用AbstractAnnotationConfigDispatcherHandlerInitializer
。但是,AbstractDispatcherHandlerInitializer
中有bug。您可以使用以下方法解决问题:
public class AppInitializer extends AbstractAnnotationConfigDispatcherHandlerInitializer {
@Override
protected Class<?>[] getConfigClasses() {
return new Class[]{
WebConfig.class,
SecurityConfig.class
};
}
protected void registerDispatcherHandler(ServletContext servletContext) {
String servletName = getServletName();
ApplicationContext applicationContext = createApplicationContext();
refreshApplicationContext(applicationContext);
registerCloseListener(servletContext, applicationContext);
HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(applicationContext)
.build();
ServletHttpHandlerAdapter handlerAdapter = new ServletHttpHandlerAdapter(httpHandler);
ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, handlerAdapter);
registration.setLoadOnStartup(1);
registration.addMapping(getServletMapping());
registration.setAsyncSupported(true);
customizeRegistration(registration);
}
}
在Spring 5.0.2.RELEASE +(计划于2017年11月15日发布)中,您可以扩展AbstractReactiveWebInitializer
。
public class AppIntializer extends AbstractReactiveWebInitializer {
@Override
protected Class<?>[] getConfigClasses() {
return new Class[]{
WebConfig.class,
SecurityConfig.class
};
}
}