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);
}
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"));
}
}
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));
}
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();
}
}
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));
}
Aggregations