List of usage examples for org.springframework.beans.factory.config ConfigurableListableBeanFactory addBeanPostProcessor
void addBeanPostProcessor(BeanPostProcessor beanPostProcessor);
From source file:cross.applicationContext.DefaultApplicationContextFactory.java
/** * Creates a new application context from the current list of * <code>applicationContextPaths</code>, interpreted as file system * resources, and the current/* ww w .j av a 2s .c o m*/ * <code>configuration</code>. * * @return the application context * @throws BeansException if any beans are not configured correctly */ public ApplicationContext createApplicationContext() throws BeansException { AbstractRefreshableApplicationContext context = null; try { final ConfiguringBeanPostProcessor cbp = new ConfiguringBeanPostProcessor(); cbp.setConfiguration(configuration); context = new FileSystemXmlApplicationContext( applicationContextPaths.toArray(new String[applicationContextPaths.size()]), context); context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() { @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory clbf) throws BeansException { clbf.addBeanPostProcessor(cbp); } }); context.refresh(); } catch (BeansException e2) { throw e2; } return context; }
From source file:cross.applicationContext.DefaultApplicationContextFactory.java
/** * Creates a new application context from the current list of * <code>applicationContextPaths</code>, interpreted as class path * resources, and the current <code>configuration</code>. * * @return the application context/*w ww. j ava 2 s . co m*/ * @throws BeansException if any beans are not configured correctly */ public ApplicationContext createClassPathApplicationContext() throws BeansException { AbstractRefreshableApplicationContext context = null; try { final ConfiguringBeanPostProcessor cbp = new ConfiguringBeanPostProcessor(); cbp.setConfiguration(configuration); context = new ClassPathXmlApplicationContext( applicationContextPaths.toArray(new String[applicationContextPaths.size()]), context); context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() { @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory clbf) throws BeansException { clbf.addBeanPostProcessor(cbp); } }); context.refresh(); } catch (BeansException e2) { throw e2; } return context; }
From source file:org.vertx.java.deploy.impl.spring.VertxApplicationContext.java
/** * @param springConfig/*w w w .jav a2s . c om*/ */ public void createContext(final String springConfig) { // Detect whether this app is configured with an XML or @Configuration. if (springConfig.endsWith(".xml")) { context = new GenericXmlApplicationContext(); context.setParent(parent); ((GenericXmlApplicationContext) context).load(springConfig); } else { context = new AnnotationConfigApplicationContext(); context.setParent(parent); try { Class<?> c = Class.forName(springConfig); ((AnnotationConfigApplicationContext) context).register(c); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(e); } } if (!listeners.isEmpty()) { for (ApplicationListener<?> listener : listeners) { context.addApplicationListener(listener); } listeners.clear(); } ConfigurableListableBeanFactory factory = context.getBeanFactory(); BeanPostProcessor vertxSupportProcessor = new VertxAwareBeanPostProcessor(vertx); factory.addBeanPostProcessor(vertxSupportProcessor); BeanPostProcessor containerSupportProcessor = new ContainerAwareBeanPostProcessor(container); factory.addBeanPostProcessor(containerSupportProcessor); }
From source file:fi.eis.applications.osgi.support.OsgiBundleXmlWebApplicationContext.java
/** * {@inheritDoc}/*from ww w . j a v a 2s . c om*/ * * Registers request/session scopes, a {@link ServletContextAwareProcessor}, * etc. */ protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { super.postProcessBeanFactory(beanFactory); beanFactory.addBeanPostProcessor(new ServletContextAwareProcessor(this.servletContext, this.servletConfig)); beanFactory.ignoreDependencyInterface(ServletContextAware.class); beanFactory.ignoreDependencyInterface(ServletConfigAware.class); beanFactory.registerResolvableDependency(ServletContext.class, this.servletContext); beanFactory.registerResolvableDependency(ServletConfig.class, this.servletConfig); WebApplicationContextUtils.registerWebApplicationScopes(beanFactory); }
From source file:com.liferay.portal.spring.extender.internal.context.ModuleBeanFactoryPostProcessor.java
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) { BeanPostProcessor beanPostProcessor = new ServiceReferenceAnnotationBeanPostProcessor(_bundleContext); configurableListableBeanFactory// w w w . ja v a2 s .com .registerSingleton(ServiceReferenceAnnotationBeanPostProcessor.class.getName(), beanPostProcessor); configurableListableBeanFactory.addBeanPostProcessor(beanPostProcessor); configurableListableBeanFactory.addBeanPostProcessor( new BeanReferenceAnnotationBeanPostProcessor(configurableListableBeanFactory)); super.postProcessBeanFactory(configurableListableBeanFactory); }
From source file:org.apache.james.container.spring.lifecycle.osgi.OsgiLifecycleBeanFactoryPostProcessor.java
@Override public void postProcessBeanFactory(BundleContext context, ConfigurableListableBeanFactory factory) throws BeansException, InvalidSyntaxException, BundleException { // We need to set the beanfactory by hand. This MAY be a bug in spring-dm but I'm not sure yet LogEnabledBeanPostProcessor loggingProcessor = new LogEnabledBeanPostProcessor(); loggingProcessor.setBeanFactory(factory); loggingProcessor.setLogProvider(logProvider); loggingProcessor.setOrder(0);/*from ww w.j a va 2 s. com*/ factory.addBeanPostProcessor(loggingProcessor); OSGIResourceAnnotationBeanPostProcessor resourceProcessor = new OSGIResourceAnnotationBeanPostProcessor(); resourceProcessor.setBeanClassLoader(factory.getBeanClassLoader()); resourceProcessor.setBeanFactory(factory); resourceProcessor.setBundleContext(context); resourceProcessor.setTimeout(60 * 1000); factory.addBeanPostProcessor(resourceProcessor); OSGIPersistenceUnitAnnotationBeanPostProcessor persistenceProcessor = new OSGIPersistenceUnitAnnotationBeanPostProcessor(); persistenceProcessor.setBeanClassLoader(factory.getBeanClassLoader()); persistenceProcessor.setBeanFactory(factory); persistenceProcessor.setBundleContext(context); persistenceProcessor.setTimeout(60 * 1000); factory.addBeanPostProcessor(persistenceProcessor); ConfigurableBeanPostProcessor configurationProcessor = new ConfigurableBeanPostProcessor(); configurationProcessor.setBeanFactory(factory); configurationProcessor.setConfigurationProvider(confProvider); configurationProcessor.setOrder(2); factory.addBeanPostProcessor(configurationProcessor); InitDestroyAnnotationBeanPostProcessor annotationProcessor = new InitDestroyAnnotationBeanPostProcessor(); annotationProcessor.setInitAnnotationType(PostConstruct.class); annotationProcessor.setDestroyAnnotationType(PreDestroy.class); factory.addBeanPostProcessor(annotationProcessor); }
From source file:com.avanza.astrix.spring.AstrixFrameworkBean.java
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { astrixContext = createAsterixContext(getDynamicConfig(applicationContext)); astrixContext.getInstance(AstrixSpringContext.class).setApplicationContext(applicationContext); for (Class<?> consumedAstrixBean : this.consumedAstrixBeans) { beanFactory.registerSingleton(consumedAstrixBean.getName(), astrixContext.getBean(consumedAstrixBean)); }/*w w w .jav a 2 s .c om*/ beanFactory.registerSingleton(AstrixSpringContext.class.getName(), astrixContext.getInstance(AstrixSpringContext.class)); beanFactory.registerSingleton(AstrixContext.class.getName(), astrixContext); beanFactory.addBeanPostProcessor(astrixContext.getInstance(AstrixBeanPostProcessor.class)); }
From source file:org.vertx.mods.spring.SpringModBase.java
@Override public final void start() { super.start(); // Make sure we're using the correct classloader Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); Assert.notNull(getContainer().getConfig(), "config object is null, which can't be good"); String springConfig = getContainer().getConfig().getString("springConfig", "applicationConfig.xml"); // Looks weird but avoids doing this twice below in the if/else block. // the vertx singleton needs to be registered before the context XML // is loaded or annotated @Configuration class is registered. ///*from ww w.ja va 2 s. co m*/ // I also like the analogy of the vertx instance being in a parent // context, as it's not instantiated in the context you really use. this.parent = new GenericApplicationContext(); ConfigurableListableBeanFactory factory = parent.getBeanFactory(); factory.registerSingleton("vertx", vertx); parent.refresh(); parent.start(); // Detect whether this app is configured with an XML or @Configuration. if (springConfig.endsWith(".xml")) { this.context = new GenericXmlApplicationContext(); context.setParent(parent); ((GenericXmlApplicationContext) context).load(springConfig); } else { this.context = new AnnotationConfigApplicationContext(); context.setParent(parent); try { Class<?> c = Class.forName(springConfig); ((AnnotationConfigApplicationContext) context).register(c); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(e); } } factory = context.getBeanFactory(); BeanPostProcessor vertxSupportProcessor = new VertxAwareBeanPostProcessor(vertx); factory.addBeanPostProcessor(vertxSupportProcessor); beforeStartApplicationContext(); context.refresh(); context.start(); context.registerShutdownHook(); afterStartApplicationContext(); }
From source file:ro.codecamp.ebp.core.util.ServerOsgiBundleXmlWebApplicationContext.java
/** * Register request/session scopes, a {@link ServletContextAwareProcessor}, etc. * /*ww w .jav a 2s. c om*/ * @see WebApplicationContextUtils#registerWebApplicationScopes(ConfigurableListableBeanFactory) */ @Override protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { super.postProcessBeanFactory(beanFactory); // Drive the kernel's bean factory post processors. BundleContext bundleContext = getBundleContext(); if (bundleContext != null) { ServiceReference sr = bundleContext.getServiceReference(OsgiBeanFactoryPostProcessor.class); if (sr != null) { OsgiBeanFactoryPostProcessor kernelPostProcessor = (OsgiBeanFactoryPostProcessor) bundleContext .getService(sr); try { kernelPostProcessor.postProcessBeanFactory(bundleContext, beanFactory); } catch (Exception e) { throw new ApplicationContextException("Kernel bean factory post processor failed", e); } finally { bundleContext.ungetService(sr); } } } beanFactory.addBeanPostProcessor(new ServletContextAwareProcessor(getServletContext(), getServletConfig())); beanFactory.ignoreDependencyInterface(ServletContextAware.class); beanFactory.ignoreDependencyInterface(ServletConfigAware.class); beanFactory.registerResolvableDependency(ServletContext.class, getServletContext()); beanFactory.registerResolvableDependency(ServletConfig.class, getServletConfig()); WebApplicationContextUtils.registerWebApplicationScopes(beanFactory); }
From source file:com.productone.spring.ServerOsgiBundleXmlWebApplicationContext.java
/** * Register request/session scopes, a {@link ServletContextAwareProcessor}, * etc./*from w w w.j a v a 2s . c o m*/ * * @see * WebApplicationContextUtils#registerWebApplicationScopes(ConfigurableListableBeanFactory) */ @Override protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { super.postProcessBeanFactory(beanFactory); // Drive the kernel's bean factory post processors. BundleContext bundleContext = getBundleContext(); if (bundleContext != null) { ServiceReference sr = bundleContext.getServiceReference(OsgiBeanFactoryPostProcessor.class.getName()); if (sr != null) { OsgiBeanFactoryPostProcessor kernelPostProcessor = (OsgiBeanFactoryPostProcessor) bundleContext .getService(sr); try { kernelPostProcessor.postProcessBeanFactory(bundleContext, beanFactory); } catch (Exception e) { throw new ApplicationContextException("Kernel bean factory post processor failed", e); } finally { bundleContext.ungetService(sr); } } } beanFactory.addBeanPostProcessor(new ServletContextAwareProcessor(getServletContext(), getServletConfig())); beanFactory.ignoreDependencyInterface(ServletContextAware.class); beanFactory.ignoreDependencyInterface(ServletConfigAware.class); beanFactory.registerResolvableDependency(ServletContext.class, getServletContext()); beanFactory.registerResolvableDependency(ServletConfig.class, getServletConfig()); WebApplicationContextUtils.registerWebApplicationScopes(beanFactory); }