Search in sources :

Example 76 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project java-design-patterns by iluwatar.

the class App method main.

/**
 * Program entry point. It starts Spring Boot application and using Apache Camel it auto-configures routes.
 *
 * @param args command line args
 */
public static void main(String[] args) throws Exception {
    // Run Spring Boot application and obtain ApplicationContext
    ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
    // Get CamelContext from ApplicationContext
    CamelContext camelContext = (CamelContext) context.getBean("camelContext");
    // Add a new routes that will handle endpoints form SplitterRoute class.
    camelContext.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("{{endpoint}}").log("ENDPOINT: ${body}");
        }
    });
    // Add producer that will send test message to an entry point in WireTapRoute
    String[] stringArray = { "Test item #1", "Test item #2", "Test item #3" };
    camelContext.createProducerTemplate().sendBody("{{entry}}", stringArray);
    SpringApplication.exit(context);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) CamelContext(org.apache.camel.CamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder)

Example 77 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project nikita-noark5-core by HiOA-ABI.

the class N5CoreApp method main.

/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 * @throws UnknownHostException if the local host name could not be resolved into an address
 */
public static void main(String[] args) throws UnknownHostException {
    ConfigurableApplicationContext context = SpringApplication.run(N5CoreApp.class, args);
    context.getBean(AfterApplicationStartup.class).afterApplicationStarts();
    Environment env = context.getEnvironment();
    String[] activeProfiles = env.getActiveProfiles();
    String profilesAsString = Arrays.toString(activeProfiles);
    logger.info("\n----------------------------------------------------------\n\t" + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\t\thttp://localhost:{}\n\t" + "External: \t\thttp://{}:{}\n\t" + "contextPath: \thttp://{}:{}{} \n\t" + "Application is running with following profile(s): {} \n\t" + "\n----------------------------------------------------------", env.getProperty("server.application.name"), env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), env.getProperty("server.servlet.context-path"), profilesAsString);
    String configServerStatus = env.getProperty("configserver.status");
    logger.info("\n----------------------------------------------------------\n\t" + "Config Server: \t{}\n----------------------------------------------------------", configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
    if (env.getProperty("spring.datasource.driver-class-name") != null && env.getProperty("spring.datasource.driver-class-name").equals("org.h2.Driver")) {
        logger.info("\n----------------------------------------------------------\n\t" + "Default profile in use. Using H2: In-memory database ({}). Access is available at." + "http://{}:{}{}{} \n\t. Make sure to use JDBC-string: jdbc:h2:mem:n5DemoDb" + "\n----------------------------------------------------------", env.getProperty("spring.jpa.database"), InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), env.getProperty("server.servlet.context-path"), env.getProperty("spring.h2.console.path"));
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AfterApplicationStartup(nikita.webapp.run.AfterApplicationStartup) Environment(org.springframework.core.env.Environment)

Example 78 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project cxf by apache.

the class BusWiringBeanFactoryPostProcessor method addDefaultBus.

public static Bus addDefaultBus(ApplicationContext ctx) {
    if (!ctx.containsBean(Bus.DEFAULT_BUS_ID)) {
        Bus b = getBusForName(Bus.DEFAULT_BUS_ID, ctx, true);
        if (ctx instanceof ConfigurableApplicationContext) {
            ConfigurableApplicationContext cctx = (ConfigurableApplicationContext) ctx;
            new BusWiringBeanFactoryPostProcessor(b).postProcessBeanFactory(cctx.getBeanFactory());
        }
    }
    return Bus.class.cast(ctx.getBean(Bus.DEFAULT_BUS_ID, Bus.class));
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Bus(org.apache.cxf.Bus)

Example 79 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project cxf by apache.

the class ConfigurerImpl method addApplicationContext.

public final void addApplicationContext(ApplicationContext ac) {
    if (!appContexts.contains(ac)) {
        appContexts.add(ac);
        List<ApplicationContext> inactiveApplicationContexts = new ArrayList<>();
        Iterator<ApplicationContext> it = appContexts.iterator();
        while (it.hasNext()) {
            ApplicationContext c = it.next();
            if (c instanceof ConfigurableApplicationContext && !((ConfigurableApplicationContext) c).isActive()) {
                inactiveApplicationContexts.add(c);
            }
        }
        // Remove the inactive application context here can avoid the UnsupportedOperationException
        for (ApplicationContext context : inactiveApplicationContexts) {
            appContexts.remove(context);
        }
        initWildcardDefinitionMap();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ArrayList(java.util.ArrayList)

Example 80 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project cxf by apache.

the class ConfigurerImplTest method testAddApplicationContext.

@Test
public void testAddApplicationContext() {
    ConfigurableApplicationContext context1 = new ClassPathXmlApplicationContext("/org/apache/cxf/configuration/spring/test-beans.xml");
    ConfigurerImpl configurer = new ConfigurerImpl();
    configurer.setApplicationContext(context1);
    // Just to simulate the OSGi's uninstall command
    context1.close();
    ConfigurableApplicationContext context2 = new ClassPathXmlApplicationContext("/org/apache/cxf/configuration/spring/test-beans.xml");
    configurer.addApplicationContext(context2);
    Set<ApplicationContext> contexts = configurer.getAppContexts();
    assertEquals("The Context's size is wrong", 1, contexts.size());
    assertTrue("The conetxts' contains a wrong application context", contexts.contains(context2));
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) BusApplicationContext(org.apache.cxf.bus.spring.BusApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Aggregations

ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)177 Test (org.junit.Test)110 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)42 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)17 ApplicationContext (org.springframework.context.ApplicationContext)17 SpringApplication (org.springframework.boot.SpringApplication)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 DataSource (javax.sql.DataSource)8 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)7 JmsListenerContainerTestFactory (org.springframework.jms.config.JmsListenerContainerTestFactory)7 MBeanServer (javax.management.MBeanServer)6 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)6 Statement (java.sql.Statement)5 ArrayList (java.util.ArrayList)5 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)5 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)5 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)5 GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)5 ObjectName (javax.management.ObjectName)4