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

Provide a mechanism for adding ApplicationContextInitializer instances [SPR-11615] #16238

Closed
spring-projects-issues opened this issue Mar 27, 2014 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Mar 27, 2014

cemo koc opened SPR-11615 and commented

Registering ApplicationContextInitializer has improved since #15938. I need to register my context ApplicationContextInitializer's instances instead of ApplicationContextInitializer's Class. Is it possible to improve the ContextLoader to pass instance of ApplicationContextInitializer.


Affects: 4.0.3

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

How would you like to pass in those ApplicationContextInitializer instances? Programmatically into a ContextLoader instance, e.g. in a WebApplicationInitializer? Since with ServletContext context-params, we can only really manage String values, it would rather have to happen on the ContextLoader itself or as a programmatically set ServletContext attribute...

Juergen

@spring-projects-issues
Copy link
Collaborator Author

cemo koc commented

I am using an subclass of ContextLoaderListener and configuring programmatically. It is very primitive but works for me:

public class SpringContextListener extends ContextLoaderListener {

   List<ApplicationContextInitializer<ConfigurableApplicationContext>> applicationContextInitializers;

   public SpringContextListener(List<ApplicationContextInitializer<ConfigurableApplicationContext>> applicationContextInitializers) {
      this.applicationContextInitializers = applicationContextInitializers;
   }

   public SpringContextListener(WebApplicationContext context, List<ApplicationContextInitializer<ConfigurableApplicationContext>> applicationContextInitializers) {
      super(context);
      this.applicationContextInitializers = applicationContextInitializers;
   }

   @Override
   protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) {
      super.customizeContext(servletContext, applicationContext);
      for (ApplicationContextInitializer<ConfigurableApplicationContext> initializer : applicationContextInitializers) {
         initializer.initialize(applicationContext);
      }
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants