Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not start spring application with webflux and websocket for ObjectPostProcessor is needed. #14810

Closed
Ayden-Franklin opened this issue Oct 13, 2018 · 8 comments
Labels
status: duplicate A duplicate of another issue

Comments

@Ayden-Franklin
Copy link

Ayden-Franklin commented Oct 13, 2018

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'.

@wilkinsona
Copy link
Member

wilkinsona commented Oct 13, 2018

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 #14069.

@wilkinsona wilkinsona added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 13, 2018
@Ayden-Franklin
Copy link
Author

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?

@wilkinsona
Copy link
Member

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.

@Ayden-Franklin
Copy link
Author

Ayden-Franklin commented Oct 17, 2018

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.

@Ayden-Franklin
Copy link
Author

Ayden-Franklin commented Oct 17, 2018

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.

@bclozel
Copy link
Member

bclozel commented Oct 17, 2018

@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

@Evgen-Krasnenkov

This comment has been minimized.

@bclozel

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

5 participants