A copy of Spring-boot 2.1.8 AnnotationConfigServletWebServerApplicationContext
,
except that it does not use its own WebServer (other super class).
Also See AnnotationConfigApplicationContext
(Same as this but uses
GenericApplicationContext instead of GenericWebApplicationContext)
In contrast to org.springframework.web.context.support.AnnotationConfigWebApplicationContext
,
this class uses the GenericWebApplicationContext, which allows registering beans using a Supplier
#registerBean(Class, Supplier, BeanDefinitionCustomizer...)
Comment From: pivotal-issuemaster
@bytewright Please sign the Contributor License Agreement!
Click here to manually synchronize the status of this Pull Request.
See the FAQ for frequently asked questions.
Comment From: pivotal-issuemaster
@bytewright Thank you for signing the Contributor License Agreement!
Comment From: bytewright
I noticed this flavor of WebApplicationContext was missing, or at least I couldn't find anything like it. Since I like working with Spring I thought: well why not just create a pull request.
Comment From: rstoyanchev
I've edited your comment to improve the formatting. You might want to check out this Mastering Markdown guide for future reference.
In particular please keep in mind that @
is a mention and generates notifications so please surround those with backquotes when it is a Java annotation.
Comment From: sbrannen
Hi @bytewright,
Thanks for submitting your first PR to the Spring Framework, and sorry for taking so long to get back to you.
You make a good point: it's not readily apparent how one can make use of #registerBean(Class, Supplier, BeanDefinitionCustomizer...)
with a WebApplicationContext
that supports annotated classes.
However, it turns out that it's relatively easy to achieve as demonstrated in the following example.
GenericWebApplicationContext context = new GenericWebApplicationContext();
AnnotatedBeanDefinitionReader annotatedBeanDefinitionReader = new AnnotatedBeanDefinitionReader(context);
context.registerBean("helloSpring", String.class, () -> "Hello, Spring!");
annotatedBeanDefinitionReader.register(UserService.class, UserRepository.class);
By using GenericWebApplicationContext
, you get access to the registerBean(...)
variants that accept a Supplier
.
By using AnnotatedBeanDefinitionReader
, you can register annotated classes (@Service
, @Controller
, etc.) with the GenericWebApplicationContext
.
After reviewing your proposal, the team has decided it does not wish to introduce AnnotationConfigGenericWebApplicationContext
since the necessary building blocks are already available as demonstrated above.
In light of that, I am closing this PR.
Comment From: sbrannen
See also:
-
27778