Summary
***** APPLICATION FAILED TO START *******
Description:
A component required a bean of type 'org.springframework.security.config.annotation.ObjectPostProcessor' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.security.config.annotation.ObjectPostProcessor' in your configuration.
Configuration
@Configuration
@EnableWebFluxSecurity
public class WebSecurityConfig {
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
...
}
...
}
@Configuration
public class WebSocketConfiguration {
@Bean
public HandlerMapping handlerMapping() {
Map<String, WebSocketHandler> map = new HashMap<>();
map.put("/websocket", new WebSocketMessageHandler());
SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
mapping.setUrlMap(map);
mapping.setOrder(-1); // before annotated controllers
return mapping;
}
@Bean
public WebSocketHandlerAdapter handlerAdapter() {
return new WebSocketHandlerAdapter();
}
}
Version
spring boot 2.0.5.RELEASE io.spring.platform:platform-bom:Cairo-SR4 org.springframework.cloud:spring-cloud-dependencies:Finchley.SR1
dependencies
... compile("org.springframework.boot:spring-boot-starter-actuator") compile("org.springframework.boot:spring-boot-starter-security") compile("org.springframework.boot:spring-boot-starter-websocket") ...
Solution
I tried again and found that it works well while using dependency of 'org.springframework:spring-websocket' instead of 'org.springframework.boot:spring-boot-starter-websocket'. In deed, spring-boot-starter-websocket depends on 'org.springframework:spring-webmvc' to case this issue. We can exclude 'org.springframework:spring-webmvc' to avoid it.
I suggest that spring-boot-starter-websocket does not depends on 'org.springframework:spring-webmvc' or there is another spring-boot-starter-webflux-websocket which depends on 'org.springframework:spring-webflux' instead of 'org.springframework:spring-webmvc'.
Comment From: wilkinsona
Thanks for the suggestion, but we don’t want to make any changes to the structure of the starters. We’ve improved the documentation in https://github.com/spring-projects/spring-boot/issues/14069.
Comment From: Ayden-Franklin
Thanks for your respond. But I don't know why you think you won't want to change the pom. Spring users should use 'org.springframework.boot:spring-boot-starter-websocket' but need excluding 'org.springframework:spring-webmvc'. It is not a good idea, I think. Is there any necessary components in the spring-webmvc for spring-boot-starter-websocket?
Comment From: wilkinsona
We don't want to change it because we don't want to have more starters than we need and we try to compose starters as much as possible. spring-boot-starter-web
provides many components that are useful for the vast majority of applications building on the Servlet stack that want to use WebSockets. That includes spring-webmvc
as, in our experience, it's unusual for a web application to only being using WebSockets.
Comment From: Ayden-Franklin
Oh, sorry. I didn't mean a web application to only being using WebSockets. I meant an application using websocket with webflux but not webmvc. I agree that spring-boot-starter-web provides many components. I know, for reactive stack we may do more as it comes later (after spring mvc). So you don't want change the spring-boot-starter-web to exclude spring-webmvc.
Any way, thanks a lot for your so great framework.
Comment From: Ayden-Franklin
By the way, I can't find any section to describe this important point. If a user starts a spring application depending on webflux, spring-security and spring-boot-starter-websocket but forgets to exclude spring-mvc they will get failure.
Comment From: bclozel
@Macrame We did improve documentation on that in the issue duplicating this one. See: https://docs.spring.io/spring-boot/docs/2.1.0.RELEASE/reference/html/boot-features-websockets.html
Comment From: Evgen-Krasnenkov
@bclozel hello. The link dosent work
Comment From: bclozel
@Evgen-Krasnenkov I've updated the link. Thanks!