Announcement Announcement Module
Collapse
No announcement yet.
Configuration in WebApplicationInitializer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 05:26 AM.
Working...
X