-
Notifications
You must be signed in to change notification settings - Fork 40.7k
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
Provide a way to create custom ApplicationContextFactory in SpringBootContextLoader #38205
Comments
I'm not too keen on adding a new attribute to @FyiurAmron If the existing |
@philwebb yes, I think it would do the trick; I completely understand your objections here, so I guess that just having an option to override that single method via |
…o v3.2.0 This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [nu.ndw.nls.geometry:nls-geometry](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | compile | minor | `3.1.2` -> `3.2.0` | --- ### Release Notes <details> <summary>spring-projects/spring-boot (nu.ndw.nls.geometry:nls-geometry)</summary> ### [`v3.2.0`](https://github.com/spring-projects/spring-boot/releases/tag/v3.2.0) [Compare Source](spring-projects/spring-boot@v3.1.2...v3.2.0) #### ⭐ New Features - Auto-configure observations for RestClients [#​38500](spring-projects/spring-boot#38500) - Add support for Oracle Free, the replacement for Oracle XE, with Testcontainers and Docker Compose [#​38476](spring-projects/spring-boot#38476) - Provide dependency management for org.crac:crac [#​38378](spring-projects/spring-boot#38378) - Add new properties for Liquibase 4.24.0 [#​38274](spring-projects/spring-boot#38274) - Provide a way to create custom ApplicationContextFactory in SpringBootContextLoader [#​38205](spring-projects/spring-boot#38205) - Report friendly error when failing to find AOT initializer [#​38188](spring-projects/spring-boot#38188) #### 🐞 Bug Fixes - Annotation based ConditionalOnBean checks can cause early initialization of FactoryBeans [#​38507](spring-projects/spring-boot#38507) - CRaC restoration fails when Actuator's running on a separate port [#​38502](spring-projects/spring-boot#38502) - App that depends on Tomcat and on Jetty's websocket-server module fails to start with IllegalStateException: WebSocketComponents has not been created [#​38286](spring-projects/spring-boot#38286) - App fails to start with a NoSuchMethodError when using Flyway 10.0.0 [#​38268](spring-projects/spring-boot#38268) - MeterRegistry throws BeanCreationNotAllowedException on shutdown [#​38240](spring-projects/spring-boot#38240) - Resolution of productionRuntimeClasspath configuration may select the wrong variant and contain a dependency's source jar [#​38233](spring-projects/spring-boot#38233) - Docker JSON parsing fails on certain locales [#​38220](spring-projects/spring-boot#38220) - FileNotFoundException is thrown serving resources due to JarUrlConnection.getLastModified() returning zero [#​38204](spring-projects/spring-boot#38204) - Failed to extract parameter names exception thrown when binding with non-enumerable property source [#​38201](https://github.com/spring-projects/spring...
As it currently stands,
SpringBootContextLoader
creates the contexts using the 0-arg c-tors, which in turn use thethis.beanFactory = new DefaultListableBeanFactory();
fromGenericApplicationContext
;beanFactory
is private and final, so as a result there is basically no simple way to inject a custom BeanFactory to the test context (or at least there is none that I am aware of).While it might seem that it should be enough for the custom BeanFactory to be tested in isolation, sometimes it's the integration with any conforming
GenericApplicationContext
subclass itself that needs to be tested (as it is in my case e.g.). Obviously, it's still possible to provide a completely custom context to tests, but for that to integrate well and to adhere to POLA it requires rewriting/copy-pasting sizeable parts of SpringBootContextLoader - while e.g. a simple annotation or annotation param to e.g.@SpringBootTest
allowing to provide a class name of the custom BeanFactory would make this trivial, and shouldn't require too much additional code in SpringBootContextLoader.And yes, this is a rare use case, but still I believe there is nothing to be lost by providing this functionality somehow, and in general having more flexibility in testing envs is always beneficial IMO. I do understand that this might get the lowest-than-low priority though, so while I'm no SB expert I can try doing a PR for this if it gets greenlit (guidelines welcome in that case), just to see how it works out.
The text was updated successfully, but these errors were encountered: