use of org.springframework.context.ConfigurableApplicationContext in project engine by craftercms.
the class SiteContextFactory method createContext.
public SiteContext createContext(String siteName) {
Map<String, String> macroValues = Collections.singletonMap(siteNameMacroName, siteName);
String resolvedRootFolderPath = macroResolver.resolveMacros(rootFolderPath, macroValues);
Context context = storeService.createContext(storeType, storeServerUrl, username, password, resolvedRootFolderPath, mergingOn, cacheOn, maxAllowedItemsInCache, ignoreHiddenFiles);
try {
SiteContext siteContext = new SiteContext();
siteContext.setStoreService(storeService);
siteContext.setSiteName(siteName);
siteContext.setContext(context);
siteContext.setStaticAssetsPath(staticAssetsPath);
siteContext.setTemplatesPath(templatesPath);
siteContext.setFreeMarkerConfig(freeMarkerConfigFactory.getObject());
siteContext.setUrlTransformationEngine(urlTransformationEngine);
siteContext.setOverlayCallback(overlayCallback);
siteContext.setRestScriptsPath(restScriptsPath);
siteContext.setControllerScriptsPath(controllerScriptsPath);
String[] resolvedConfigPaths = new String[configPaths.length];
for (int i = 0; i < configPaths.length; i++) {
resolvedConfigPaths[i] = macroResolver.resolveMacros(configPaths[i], macroValues);
}
String[] resolvedAppContextPaths = new String[applicationContextPaths.length];
for (int i = 0; i < applicationContextPaths.length; i++) {
resolvedAppContextPaths[i] = macroResolver.resolveMacros(applicationContextPaths[i], macroValues);
}
ResourceLoader resourceLoader = new ContentStoreResourceLoader(siteContext);
HierarchicalConfiguration<?> config = getConfig(siteContext, resolvedConfigPaths, resourceLoader);
URLClassLoader classLoader = getClassLoader(siteContext);
ScriptFactory scriptFactory = getScriptFactory(siteContext, classLoader);
ConfigurableApplicationContext appContext = getApplicationContext(siteContext, classLoader, config, resolvedAppContextPaths, resourceLoader);
siteContext.setConfigPaths(resolvedConfigPaths);
siteContext.setApplicationContextPaths(resolvedAppContextPaths);
siteContext.setGroovyClassesPath(groovyClassesPath);
siteContext.setScriptFactory(scriptFactory);
siteContext.setConfig(config);
siteContext.setGlobalApplicationContext(globalApplicationContext);
siteContext.setApplicationContext(appContext);
siteContext.setClassLoader(classLoader);
executeInitScript(siteContext, scriptFactory);
Scheduler scheduler = scheduleJobs(siteContext);
siteContext.setScheduler(scheduler);
return siteContext;
} catch (Exception e) {
// Destroy context if the site context creation failed
storeService.destroyContext(context);
throw e;
}
}
use of org.springframework.context.ConfigurableApplicationContext in project uPortal by Jasig.
the class PortalApplicationContextLocator method shutdown.
/**
* If the ApplicationContext returned by {@link #getApplicationContext()} is 'portal managed'
* the shutdown hook for the context is called, closing and cleaning up all spring managed
* resources.
*
* <p>If the ApplicationContext returned by {@link #getApplicationContext()} is actually a
* WebApplicationContext this method does nothing but log an error message.
*/
public static void shutdown() {
if (applicationContextCreator.isCreated()) {
final ConfigurableApplicationContext applicationContext = applicationContextCreator.get();
applicationContext.close();
} else {
final IllegalStateException createException = new IllegalStateException("No portal managed ApplicationContext has been created, there is nothing to shutdown.");
getLogger().error(createException, createException);
}
}
use of org.springframework.context.ConfigurableApplicationContext in project java-function-invoker by projectriff.
the class BeanCountingApplicationListener method onApplicationEvent.
@SuppressWarnings("resource")
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
if (!event.getApplicationContext().equals(this.context)) {
return;
}
int count = 0;
ConfigurableApplicationContext context = event.getApplicationContext();
String id = context.getId();
List<String> names = new ArrayList<>();
while (context != null) {
count += context.getBeanDefinitionCount();
names.addAll(Arrays.asList(context.getBeanDefinitionNames()));
context = (ConfigurableApplicationContext) context.getParent();
}
logger.info("Bean count: " + id + "=" + count);
logger.debug("Bean names: " + id + "=" + names);
try {
logger.info("Class count: " + id + "=" + ManagementFactory.getClassLoadingMXBean().getTotalLoadedClassCount());
} catch (Exception e) {
}
if (isSpringBootApplication(sources(event))) {
try {
logger.info(MARKER);
} catch (Exception e) {
}
}
}
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(final String... args) throws UnknownHostException {
//SpringApplication app = new SpringApplication(N5CoreApp.class);
//SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
ConfigurableApplicationContext context = SpringApplication.run(CONFIGS, 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("spring.application.name"), env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), env.getProperty("server.contextPath"), 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 (profilesAsString != null && profilesAsString.contains("de")) {
logger.info("\n----------------------------------------------------------\n\t" + "Dev/demo mode: In-memory database ({}) in use. See http://localhost:8082 . Use following JDBC-string: jdbc:h2:mem:n5DemoDb/jdbc:h2:mem:n5DevDb" + "\n----------------------------------------------------------", env.getProperty("spring.jpa.database"));
}
}
use of org.springframework.context.ConfigurableApplicationContext in project dubbo by alibaba.
the class Spring3CompatibilityTest method startupProvider.
private static ConfigurableApplicationContext startupProvider() {
ConfigurableApplicationContext context = startupApplicationContext(ProviderConfiguration.class);
System.out.println("Startup Provider ...");
return context;
}
Aggregations