Skip to content

Introduce AnnotationConfigGenericWebApplicationContext #24236

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

Closed
wants to merge 1 commit into from

Conversation

bytewright
Copy link

@bytewright bytewright commented Dec 20, 2019

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

 * A copy of Spring-boot 2.1.8 {@link AnnotationConfigServletWebServerApplicationContext},
 * except that it does not use its own WebServer (other super class).
 * <p>
 * Also See {@link AnnotationConfigApplicationContext} (Same as this but uses
 * GenericApplicationContext instead of GenericWebApplicationContext)
 * <p>
 * In contrast to {@link org.springframework.web.context.support.AnnotationConfigWebApplicationContext},
 * this class uses the GenericWebApplicationContext, which allows registering beans using a Supplier
 * {@link #registerBean(Class, Supplier, BeanDefinitionCustomizer...)}
 * <p>
 * See javadoc of superclass {@link GenericWebApplicationContext} for more information.
@pivotal-issuemaster
Copy link

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 20, 2019
@pivotal-issuemaster
Copy link

@bytewright Thank you for signing the Contributor License Agreement!

@bytewright
Copy link
Author

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.

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Dec 20, 2019

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.

@rstoyanchev rstoyanchev added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement in: web Issues in web modules (web, webmvc, webflux, websocket) labels Dec 20, 2019
@rstoyanchev rstoyanchev self-assigned this Dec 3, 2021
@rstoyanchev rstoyanchev assigned sbrannen and unassigned rstoyanchev Dec 7, 2021
@rstoyanchev rstoyanchev added type: documentation A documentation task and removed status: waiting-for-triage An issue we've not yet triaged or decided on type: enhancement A general enhancement labels Dec 7, 2021
@rstoyanchev rstoyanchev added this to the Triage Queue milestone Dec 7, 2021
@sbrannen sbrannen changed the title Create AnnotationConfigGenericWebApplicationContext.java Introduce AnnotationConfigGenericWebApplicationContext Dec 7, 2021
@sbrannen
Copy link
Member

sbrannen commented Dec 7, 2021

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.

@sbrannen sbrannen closed this Dec 7, 2021
@sbrannen sbrannen removed this from the Triage Queue milestone Dec 7, 2021
@sbrannen sbrannen added status: declined A suggestion or change that we don't feel we should currently apply and removed for: team-meeting labels Dec 7, 2021
@sbrannen
Copy link
Member

sbrannen commented Dec 7, 2021

@sbrannen sbrannen removed type: documentation A documentation task in: core Issues in core modules (aop, beans, core, context, expression) labels Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants