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

WebSessionIdResolverAutoConfiguration should only be active in a reactive web application #29669

Closed
janssk1 opened this issue Feb 7, 2022 · 4 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@janssk1
Copy link

janssk1 commented Feb 7, 2022

We are using an ApplicationContext hierarchy in our Spring Boot application. Each child application has their own webserver using a unique port, that is configured through a custom child specific properties file. This works fine in spring boot 2.5. However, after upgrading to 2.6(.2), the single parent context contains already a ServerProperties instance, causing all child component to reuse that one instead of creating their own, breaking our configuration.

After some digging, the problem seems to be a change in WebSessionIdResolverAutoConfiguration. Since 2.6, that one requires ServerProperties, causing it to be added to the root context.

As a workaround, we have explicitly removed the WebSessionIdResolverAutoConfiguration from our root context (using EnableAutoConfiguration(exclude={WebSessionIdResolverAutoConfiguration.class})).

I see a similar issue was raised and fixed when migrating from 2.2 to 2.3 (#21789).

Our current way of providing different servers per child component relies on the assumption that the parent context does not contain an instance of ServerProperties. This seems to be a brittle assumption. Is there a better (more stable) approach to achieve what we are trying to do ?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 7, 2022
@wilkinsona
Copy link
Member

Thanks for the report, @janssk1. It looks as if we could apply a fix that's similar to the fix for #21789 but I'm wondering why WebSessionIdResolverAutoConfiguration isn't @ConditionalOnWebApplication. I'm also curious to know if that would solve the problem for your context hierarchy. To that end, can you please provide a complete yet minimal sample project that reproduces the problem you're facing?

@wilkinsona wilkinsona added for: team-meeting An issue we'd like to discuss as a team to make progress status: waiting-for-feedback We need additional information before we can continue labels Feb 7, 2022
@janssk1
Copy link
Author

janssk1 commented Feb 7, 2022

I have updated the example from the previous ticket: janssk1/spring-context-hierarchy@d4d8cff

As soon as reactor-core is in the classpath (in our case, it was on the classpath for an unrelated reason), the WebSessionIdResolverAutoConfiguration kicks in and instantiates ServerProperties

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 7, 2022
@wilkinsona
Copy link
Member

Thank you. As I'd hoped, marking WebSessionIdResolverAutoConfiguration as @ConditionalOnWebApplication(type = Type.REACTIVE) allows your application to start using ports 8081 and 8082. It also continues to work after updating the sample to be a reactive web application. As part of applying that fix, we should also review other places where @EnableConfigurationProperties(ServerProperties.class) is used and ensure that they're only triggered in a web application.

@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided for: team-meeting An issue we'd like to discuss as a team to make progress labels Feb 7, 2022
@wilkinsona wilkinsona added this to the 2.6.x milestone Feb 7, 2022
@wilkinsona
Copy link
Member

WebSessionIdResolverAutoConfiguration seems to be the only place that's affected. All other uses of @EnableConfigurationProperties(ServerProperties.class) are protected with a web application condition.

@wilkinsona wilkinsona changed the title ServerProperties are always loaded since spring boot 2.6, causing context hierarchies to break WebSessionIdResolverAutoConfiguration should only be active in a reactive web application Feb 11, 2022
@wilkinsona wilkinsona self-assigned this Feb 11, 2022
@wilkinsona wilkinsona modified the milestones: 2.6.x, 2.6.4 Feb 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants