Announcement Announcement Module
Collapse
No announcement yet.
Init app context that depends on ApplicationProfile Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Init app context that depends on ApplicationProfile

    Hi. I created ApplicationProfiles class

    Code:
    public final class ApplicationProfiles {
    
        public static final String DEVELOPMENT = "development";
    
        public static final String TEST = "test";
    
        public static final String PRODUCTION = "production";
    
        private ApplicationProfiles() {
        }
    
    }
    and ApplicationConfig class

    Code:
    @Configuration
    public class ApplicationConfig {
    
        @Configuration
        @Profile( ApplicationProfiles.DEVELOPMENT )
        @ImportResource(value = { "classpath:application-config.xml" })
        static class DevelopmentEnvironmentConfiguration {
    
        }
    
        @Configuration
        @Profile( ApplicationProfiles.TEST )
        @ImportResource(value = { "classpath:application-test-config.xml" })
        static class TestEnvironmentConfiguration {
    
        }
    
        @Configuration
        @Profile( ApplicationProfiles.PRODUCTION )
        @ImportResource(value = { "classpath:application-config.xml" })
        static class ProductionEnvironmentConfiguration {
    
        }
    
    }
    For test I am use this code

    Code:
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(classes = { ApplicationConfig.class }, loader = AnnotationConfigContextLoader.class)
    @ActiveProfiles( profiles = {ApplicationProfiles.TEST} )
    public class MyTest {
    ...
    How I can load my app context with other profile ? (I do not have any main method)

    I want init ApplicationContext as a static field...
Working...
X