List of usage examples for org.springframework.context.support AbstractApplicationContext refresh
@Override public void refresh() throws BeansException, IllegalStateException
From source file:org.settings4j.helper.spring.ByteArrayXMLApplicationContext.java
/** * Static method to get a single Bean from a Spring Configuration XML. * * @param content The Spring configuration XML as byte[]. * @param beanName The bean name/identifier. * @return The Bean-Object or <code>null</code>. */// w w w . j a v a2s . c o m public static Object getBean(final byte[] content, final String beanName) { final AbstractApplicationContext context = new ByteArrayXMLApplicationContext(content); context.refresh(); final Object result = context.getBean(beanName); context.close(); return result; }
From source file:org.rivetlogic.utils.IntegrationUtils.java
public static BeanFactory getBeanFactory() throws IOException { if (beanFactory == null) { synchronized (beanFactoryLockObj) { if (beanFactory == null) { PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); AbstractApplicationContext context = new ClassPathXmlApplicationContext( "application-context.xml"); Resource resource = new FileSystemResource("cma-cfg.properties"); Properties properties = new Properties(); properties.load(resource.getInputStream()); configurer.setProperties(properties); context.addBeanFactoryPostProcessor(configurer); context.refresh(); beanFactory = context.getBeanFactory(); }//from w ww. ja v a2 s . co m } } return beanFactory; }
From source file:com.github.exper0.efilecopier.ftp.CachedAdapterFactory.java
private AbstractApplicationContext getParent(ReportSettings settings) { final String key = String.format("%s:%d", settings.getHost(), settings.getPort()); AbstractApplicationContext context = parents.get(key); if (context == null) { context = new GenericApplicationContext(); DefaultFtpSessionFactory factory = new DefaultFtpSessionFactory(); factory.setUsername(settings.getUser()); factory.setPassword(settings.getPassword()); factory.setHost(settings.getHost()); factory.setPort(settings.getPort()); context.getBeanFactory().registerSingleton(FACTORY_NAME, factory); context.refresh(); parents.put(key, context);/*from ww w . java 2 s. co m*/ } return context; }
From source file:com.github.exper0.efilecopier.ftp.DynamicFtpChannelResolver.java
private AbstractApplicationContext getContext(ReportSettings settings) { final String key = String.format("%s:%d", settings.getHost(), settings.getPort()); AbstractApplicationContext context = roots.get(key); if (context == null) { context = new GenericApplicationContext(); DefaultFtpSessionFactory factory = new DefaultFtpSessionFactory(); factory.setUsername(settings.getUser()); factory.setPassword(settings.getPassword()); factory.setHost(settings.getHost()); factory.setPort(settings.getPort()); context.getBeanFactory().registerSingleton("session.factory", factory); context.refresh(); }/*from w ww. j a v a 2 s. c o m*/ return context; }
From source file:com.easyjf.container.impl.SpringContainer.java
public void init() { logger.info(I18n.getLocaleMessage("ext.began.pring.containers.initialization")); if (factory == null) { if (this.configLocation != null && !"".equals(this.configLocation)) { this.factory = new ClassPathXmlApplicationContext(this.configLocation.split(";")); } else {// w ww . ja v a 2s. c o m this.factory = new ClassPathXmlApplicationContext("classpath: applicationContext.xml"); } } if (factory instanceof AbstractApplicationContext) { AbstractApplicationContext context = (AbstractApplicationContext) factory; if (factory instanceof ConfigurableWebApplicationContext) { // ?? ConfigurableWebApplicationContext webContext = (ConfigurableWebApplicationContext) factory; if (parent != null && parent instanceof WebContextContainer) { webContext.setServletContext(((WebContextContainer) parent).getServletContext()); } if (!haveStart) { context.refresh(); haveStart = true; } } if (parent != null && parent instanceof WebContextContainer) { this.registerWebContext(((WebContextContainer) parent).getServletContext()); } } logger.info(I18n.getLocaleMessage("ext.Spring.container.initialized")); }
From source file:org.rivetlogic.export.components.XmlExtractRequestProcessor.java
private void initializeCMSCreds(Ticket ticketParam) throws IOException, AuthenticationFailure, CmaRuntimeException { // set up the bean factory if (beanFactory == null) { PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); AbstractApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml"); Resource resource = context.getResource("classpath:core/cma-cfg.properties"); Properties properties = new Properties(); properties.load(resource.getInputStream()); configurer.setProperties(properties); context.addBeanFactoryPostProcessor(configurer); context.refresh(); beanFactory = context.getBeanFactory(); authService = (AuthenticationService) beanFactory.getBean("authenticationService", AuthenticationServiceImpl.class); }// w ww. j a va 2 s .c o m // get a ticket if (this.ticket == null) { if (ticketParam != null) { this.ticket = ticketParam; } else { this.ticket = authService.authenticate(cmaUrl, cmaUsername, cmaPassword.toCharArray()); } } try { authService.validate(ticket); } catch (InvalidTicketException e) { log.debug("ticket invalid, getting a new one."); ticket = authService.authenticate(cmaUrl, cmaUsername, cmaPassword.toCharArray()); } }
From source file:org.rivetlogic.export.components.AbstractXMLProcessor.java
private void initialize() throws AuthenticationFailure, CmaRuntimeException, IOException { if (ticket == null) { if (beanFactory == null) { PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); AbstractApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml"); Resource resource = context.getResource("classpath:core/cma-cfg.properties"); Properties properties = new Properties(); properties.load(resource.getInputStream()); configurer.setProperties(properties); context.addBeanFactoryPostProcessor(configurer); context.refresh(); beanFactory = context.getBeanFactory(); }/*from w w w.j a va 2 s. c o m*/ authService = (AuthenticationService) beanFactory.getBean("authenticationService", AuthenticationServiceImpl.class); ticket = authService.authenticate(cmaUrl, cmaUsername, cmaPassword.toCharArray()); nodeService = (NodeService) beanFactory.getBean("nodeService", NodeServiceImpl.class); searchService = (SearchService) beanFactory.getBean("searchService", SearchServiceImpl.class); contentService = (ContentServiceImpl) beanFactory.getBean("contentService", ContentServiceImpl.class); } try { authService.validate(ticket); } catch (InvalidTicketException e) { logger.debug("ticket invalid, getting a new one."); ticket = authService.authenticate(cmaUrl, cmaUsername, cmaPassword.toCharArray()); } }
From source file:org.age.services.worker.internal.DefaultWorkerService.java
private void prepareContext(final @NonNull AbstractApplicationContext taskContext) { assert nonNull(taskContext); // Configure communication facilities (as singletons) final ConfigurableListableBeanFactory beanFactory = taskContext.getBeanFactory(); final Map<String, CommunicationFacility> facilitiesMap = applicationContext .getBeansOfType(CommunicationFacility.class); communicationFacilities.addAll(facilitiesMap.values()); // Add services log.debug("Registering facilities and adding them as listeners for messages."); communicationFacilities.forEach(service -> { service.subscribedTypes().forEach(key -> workerMessageListeners.get(key).add(service)); log.debug("Registering {} as {} in application context.", service.getClass().getSimpleName(), service); beanFactory.registerSingleton(service.getClass().getSimpleName(), service); });//from ww w . j a v a 2 s . co m // Refreshing the context taskContext.refresh(); currentContext = taskContext; }
From source file:org.jahia.bundles.extender.jahiamodules.Activator.java
private synchronized void start(final Bundle bundle) { final JahiaTemplatesPackage jahiaTemplatesPackage = templatePackageRegistry.lookupByBundle(bundle); if (jahiaTemplatesPackage == null) { logger.info("--- Bundle {} is starting but has not yet been parsed. Delaying its startup.", bundle); return;//from w w w. j a va2 s . c o m } ModuleState.State state = getModuleState(bundle).getState(); if (state == ModuleState.State.ERROR_WITH_DEFINITIONS || state == ModuleState.State.INCOMPATIBLE_VERSION) { return; } if (!checkImported(jahiaTemplatesPackage)) { setModuleState(bundle, ModuleState.State.WAITING_TO_BE_IMPORTED, null); return; } logger.info("--- Start DX OSGi bundle {} --", getDisplayName(bundle)); long startTime = System.currentTimeMillis(); templatePackageRegistry.register(jahiaTemplatesPackage); jahiaTemplatesPackage.setActiveVersion(true); templatesService.fireTemplatePackageRedeployedEvent(jahiaTemplatesPackage); // scan for resource and call observers boolean hasSpringFile = hasSpringFile(bundle); for (final Map.Entry<BundleURLScanner, BundleObserver<URL>> scannerAndObserver : extensionObservers .entrySet()) { final List<URL> foundURLs = scannerAndObserver.getKey().scan(bundle); if (!foundURLs.isEmpty()) { // rules may use Global objects from his own spring beans, so we delay the rules registration until the spring context is initialized // to insure that potential global objects are available before rules executions if (DRL_SCANNER.equals(scannerAndObserver.getKey()) && hasSpringFile) { logger.info( "--- Rules registration for bundle {} has been delayed until its Spring context is initialized --", getDisplayName(bundle)); jahiaTemplatesPackage.doExecuteAfterContextInitialized( new JahiaTemplatesPackage.ContextInitializedCallback() { @Override public void execute(AbstractApplicationContext context) { scannerAndObserver.getValue().addingEntries(bundle, foundURLs); } }); } else { scannerAndObserver.getValue().addingEntries(bundle, foundURLs); } } } registerHttpResources(bundle); long totalTime = System.currentTimeMillis() - startTime; if (initializedBundles.remove(bundle)) { //auto deploy bundle according to bundle configuration try { JCRTemplate.getInstance().doExecuteWithSystemSessionAsUser(null, null, null, new JCRCallback<Boolean>() { @Override public Boolean doInJCR(JCRSessionWrapper session) throws RepositoryException { templatesService.autoInstallModulesToSites(jahiaTemplatesPackage, session); session.save(); return null; } }); } catch (RepositoryException e) { logger.error("Error while initializing module content for module " + jahiaTemplatesPackage, e); } } // check for script engine factories String errorMessage = null; try { scriptEngineManager.addScriptEngineFactoriesIfNeeded(bundle); } catch (Exception e) { logger.error("Unable to add script engine factories", e); errorMessage = e.getMessage(); } logger.info("--- Finished starting DX OSGi bundle {} in {}ms --", getDisplayName(bundle), totalTime); if (hasSpringFile) { setModuleState(bundle, ModuleState.State.SPRING_STARTING, errorMessage); try { final AbstractApplicationContext contextToStartForModule = BundleUtils .getContextToStartForModule(bundle); if (contextToStartForModule != null) { contextToStartForModule.refresh(); } } catch (Exception e) { logger.error("Unable to create application context for [" + bundle.getSymbolicName() + "]", e); } } else { setModuleState(bundle, ModuleState.State.STARTED, errorMessage); } }