-
Notifications
You must be signed in to change notification settings - Fork 41.6k
Description
Hi, this is a first-timers-only issue. This means we've worked to make it more legible to folks who either haven't contributed to our codebase before, or even folks who haven't contributed to open source before.
If that's you, we're interested in helping you take the first step and can answer questions and help you out as you do. Note that we're especially interested in contributions from people from groups underrepresented in free and open source software!
If you have contributed before, consider leaving this one for someone new, and looking through our general ideal-for-contribution issues. Thanks!
Background
Spring Boot auto-configures an OpenEntityManagerInViewInterceptor in JpaWebConfiguration. When the user provides their own equivalent bean, the auto-configured interceptor should back off.
Problem
The auto-configuration is conditional on there being no OpenEntityManagerInViewInterceptor or OpenEntityManagerInViewFilter:
Lines 212 to 213 in 99656b9
| @ConditionalOnMissingBean({ OpenEntityManagerInViewInterceptor.class, | |
| OpenEntityManagerInViewFilter.class }) |
This means that it correctly backs off when the user defines a bean of either type, however it does not back off if the user defines a FilterRegistrationBean<OpenEntityManagerInViewFilter> bean unless they also define an OpenEntityManagerInViewFilter bean. Defining only a FilterRegistrationBean<OpenEntityManagerInViewFilter> bean should be sufficient to cause the auto-configuration of the interceptor to back off.
Solution
Rather than considering OpenEntityManagerInViewFilter in the @ConditionalOnMissingBean, @ConditionalOnMissingFilterBean(OpenEntityManagerInViewFilter.class) should be used instead. This will cause the auto-configured filter to back off when there is a user-defined OpenEntityManagerInViewFilter or FilterRegistrationBean<OpenEntityManagerInViewFilter> bean.
There is an existing test that checks the OpenEntityManagerInViewFilter case:
Lines 149 to 159 in 99656b9
| @Test | |
| public void openEntityManagerInViewInterceptorIsNotRegisteredWhenFilterPresent() { | |
| new WebApplicationContextRunner() | |
| .withPropertyValues("spring.datasource.generate-unique-name=true") | |
| .withUserConfiguration(TestFilterConfiguration.class) | |
| .withConfiguration(AutoConfigurations.of( | |
| DataSourceAutoConfiguration.class, | |
| TransactionAutoConfiguration.class, this.autoConfiguredClass)) | |
| .run((context) -> assertThat(context) | |
| .doesNotHaveBean(OpenEntityManagerInViewInterceptor.class)); | |
| } |
A new test for the filter registration bean case should be added. Rather than using TestFilterConfiguration it should use a new TestFilterRegistrationConfiguration class that defines a FilterRegistrationBean<OpenEntityManagerInViewFilter> bean.
Steps to Fix
- Claim this issue with a comment below and ask any clarifying questions you need
- Set up a repository locally following the Contributing Guidelines
- Try to fix the issue following the steps above
- Commit your changes and start a pull request.