Results 1 to 1 of 1

Thread: Configuration in WebApplicationInitializer

Hybrid View

  1. #1

    Question Configuration in WebApplicationInitializer

    Hi all

    I'm using Spring code based configuration to setup my webapp which works fine.

    Initializer:
    Code:
    public class AppInit implements WebApplicationInitializer {
        @Override
        public void onStartup(final ServletContext container) {
            // Create the 'root' Spring application context
            final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
            rootContext.register(AppConfig.class);
    
            // Manage the lifecycle of the root application context
            container.addListener(new ContextLoaderListener(rootContext));
            container.addListener(new RequestContextListener());
            container.addListener(new Log4jConfigListener());
    
            // Add filters
            // TODO: Need configuration values here
        }
    }
    Configuration:
    Code:
    @Configuration
    @ComponentScan(basePackages = "package")
    @PropertySource("${applicationConfigLocation}")
    // importing other configuration classes
    // ...
    public class AppConfig {
    
        @Bean
        public PropertySourcesPlaceholderConfigurer pspc() {
            return new PropertySourcesPlaceholderConfigurer();
        }
    }
    What I'm trying to do now is configuring my filters with properties from the same source as @PropertySource("${applicationConfigLocation}").
    ${applicationConfigLocation} is defined in the context of the web application and points to some property file in the classpath.

    Is there any good/clean way to do this? Something like telling Spring to load the configuration already in WebApplicationInitializer#onStartup? If possible, I'd like to prevent manually loading the property file..

    Cheers
    - Ada
    Last edited by andreas.antener; Aug 8th, 2012 at 05:26 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •