List of usage examples for org.springframework.context.support AbstractApplicationContext getBeanFactory
@Override public abstract ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException;
From source file:com.maxpowered.amazon.advertising.api.app.App.java
public static String getOptionDefaultBasedOnSpringProperty(final AbstractApplicationContext ctx, final String propName, final String defaultStr) { String value = ctx.getBeanFactory().resolveEmbeddedValue("${" + propName + "}"); if (value == null) { value = defaultStr;// w w w. j av a 2 s . c om } return value; }
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();/* www . j ava2 s . com*/ beanFactory = context.getBeanFactory(); } } } return beanFactory; }
From source file:de.javadesign.cdi.extension.spring.SpringBeanIntegrationExtension.java
/** * Register found beans from the application context. * /* ww w. jav a2 s. c o m*/ * @param applicationContext * the spring application context * @param event * the AfterBeanDiscoveryEvent */ private void registerBeans(final AbstractApplicationContext applicationContext, final AfterBeanDiscovery event, final BeanManager beanManager) { final String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames(); final ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory(); Bean<?> springBean = null; for (final String beanName : beanDefinitionNames) { final BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); springBean = createBean(beanName, beanDefinition, beanFactory, beanManager); if (springBean != null) { LOGGER.debug("Register Bean: {}.", springBean); event.addBean(springBean); } } }
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();//from w w w. j a v a 2 s . co m parents.put(key, context); } 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 w w . ja v a 2 s . c o m } return context; }
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 w ww .j a v a2 s . c om*/ // Refreshing the context taskContext.refresh(); currentContext = taskContext; }
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();//from ww w . ja v a 2s. c o m beanFactory = context.getBeanFactory(); authService = (AuthenticationService) beanFactory.getBean("authenticationService", AuthenticationServiceImpl.class); } // 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();//from w ww. ja v a 2 s . c o m beanFactory = context.getBeanFactory(); } 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()); } }