Java Code Examples for org.springframework.context.ApplicationContext.getAutowireCapableBeanFactory()

The following are Jave code examples for showing how to use getAutowireCapableBeanFactory() of the org.springframework.context.ApplicationContext class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: -artemis-disruptor-miaosha   File: BeanRegisterUtils.java   View Source Code Vote up 5 votes
public static void registerSingleton(ApplicationContext applicationContext, String beanName, Object singletonObject) {

    AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
    if (!SingletonBeanRegistry.class.isAssignableFrom(beanFactory.getClass())) {
      throw new IllegalArgumentException(
          "ApplicationContext: " + applicationContext.getClass().toString()
              + " doesn't implements SingletonBeanRegistry, cannot register JMS connection at runtime");
    }

    SingletonBeanRegistry beanDefinitionRegistry = (SingletonBeanRegistry) beanFactory;
    beanDefinitionRegistry.registerSingleton(beanName, singletonObject);

  }
 
Example 2
Project: daros-dynamic   File: DynamicRegisterGroovyFile.java   View Source Code Vote up 5 votes
@Autowired
public void setApplicationContext(ApplicationContext ctx) {
    if (!DefaultListableBeanFactory.class.isAssignableFrom(ctx.getAutowireCapableBeanFactory().getClass())) {
        throw new IllegalArgumentException("BeanFactory must be DefaultListableBeanFactory type");
    }
    this.ctx = ctx;
    this.beanFactory = (DefaultListableBeanFactory) ctx.getAutowireCapableBeanFactory();
}
 
Example 3
Project: artemis-disruptor-miaosha   File: BeanRegisterUtils.java   View Source Code Vote up 5 votes
public static void registerSingleton(ApplicationContext applicationContext, String beanName, Object singletonObject) {

    AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
    if (!SingletonBeanRegistry.class.isAssignableFrom(beanFactory.getClass())) {
      throw new IllegalArgumentException(
          "ApplicationContext: " + applicationContext.getClass().toString()
              + " doesn't implements SingletonBeanRegistry, cannot register JMS connection at runtime");
    }

    SingletonBeanRegistry beanDefinitionRegistry = (SingletonBeanRegistry) beanFactory;
    beanDefinitionRegistry.registerSingleton(beanName, singletonObject);

  }
 
Example 4
Project: kaltura-ce-sakai-extension   File: KalturaEntityProducer.java   View Source Code Vote up 5 votes
public void init() {
    if (log.isDebugEnabled()) log.debug("kaltura EP.init()");
    try {
        entityManager.registerEntityProducer(this, REFERENCE_ROOT);
        log.info("Registered kaltura entity producer as: "+ REFERENCE_ROOT);

        // AZ - now we need to do some serious spring gymnastics to get our service into the main Sakai AC
        // get the main sakai AC (it will be the parent of our AC)
        ApplicationContext sakaiAC = applicationContext.getParent();
        if (sakaiAC != null && sakaiAC instanceof ConfigurableApplicationContext) {
            // only ConfigurableApplicationContext - or higher - can register singletons
            Object currentKEP = ComponentManager.get(KalturaEntityProducer.class.getName());
            // check if something is already registered
            if (currentKEP != null) {
                log.info("Found existing "+KalturaEntityProducer.class.getName()+" in the ComponentManager: "+currentKEP);
                // attempt to unregister the existing bean (otherwise the register call will fail)
                try {
                    // only DefaultListableBeanFactory - or higher - can unregister singletons
                    DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory) sakaiAC.getAutowireCapableBeanFactory();
                    dlbf.destroySingleton(KalturaEntityProducer.class.getName());
                    log.info("Removed existing "+KalturaEntityProducer.class.getName()+" from the ComponentManager");
                } catch (Exception e) {
                    log.warn("FAILED attempted removal of kaltura bean: "+e);
                }
            }
            // register this EP with the sakai AC
            ((ConfigurableApplicationContext)sakaiAC).getBeanFactory().registerSingleton(KalturaEntityProducer.class.getName(), this);
        }
        // now verify if we are good to go
        if (ComponentManager.get(KalturaEntityProducer.class.getName()) != null) {
            log.info("Found "+KalturaEntityProducer.class.getName()+" in the ComponentManager");
        } else {
            log.warn("FAILED to insert and lookup "+KalturaEntityProducer.class.getName()+" in the Sakai ComponentManager, archive imports for kaltura will not work");
        }
    } catch (Exception ex) {
        log.warn("kaltura EP.init(): "+ex, ex);
    }
}
 
Example 5
Project: martini-core   File: StepsAnnotationProcessor.java   View Source Code Vote up 5 votes
@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {
	this.context = context;
	AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory();
	checkState(ConfigurableListableBeanFactory.class.isInstance(beanFactory),
		"Martini requires the use of a ConfigurableListableBeanFactory");
	ConfigurableListableBeanFactory configurable = ConfigurableListableBeanFactory.class.cast(beanFactory);
	callbacks = ImmutableList.<ReflectionUtils.MethodCallback>builder()
		.add(new MartiniAnnotationCallback<>(Given.class, GivenContainer.class, configurable))
		.add(new MartiniAnnotationCallback<>(And.class, AndContainer.class, configurable))
		.add(new MartiniAnnotationCallback<>(When.class, WhenContainer.class, configurable))
		.add(new MartiniAnnotationCallback<>(Then.class, ThenContainer.class, configurable))
		.build();
}
 
Example 6
Project: spring-boot-quartz-demo   File: AutowiringSpringBeanJobFactory.java   View Source Code Vote up 4 votes
@Override
public void setApplicationContext(final ApplicationContext context) {
    beanFactory = context.getAutowireCapableBeanFactory();
}
 
Example 7
Project: dhus-core   File: AutowiringJobFactory.java   View Source Code Vote up 4 votes
@Override
public void setApplicationContext (final ApplicationContext context)
{
   beanFactory = context.getAutowireCapableBeanFactory ();
}
 
Example 8
Project: sentry   File: AutowiringSpringBeanJobFactory.java   View Source Code Vote up 4 votes
@Override
public void setApplicationContext(final ApplicationContext context) {
    beanFactory = context.getAutowireCapableBeanFactory();
}
 
Example 9
Project: quartz-manager   File: AutowiringSpringBeanJobFactory.java   View Source Code Vote up 4 votes
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
	beanFactory = applicationContext.getAutowireCapableBeanFactory();
}
 
Example 10
Project: webcron   File: AutowiringSpringBeanJobFactory.java   View Source Code Vote up 4 votes
public void setApplicationContext(final ApplicationContext context) {
    beanFactory = context.getAutowireCapableBeanFactory();
}
 
Example 11
Project: cf-mta-deploy-service   File: AutowiringSpringBeanJobFactory.java   View Source Code Vote up 4 votes
public void setApplicationContext(final ApplicationContext context) {
    beanFactory = context.getAutowireCapableBeanFactory();
}
 
Example 12
Project: webside   File: AutowiringSpringBeanJobFactory.java   View Source Code Vote up 4 votes
public void setApplicationContext(final ApplicationContext context) {
	beanFactory = context.getAutowireCapableBeanFactory();
}
 
Example 13
Project: taboola-cronyx   File: DelegatingQuartzJobFactory.java   View Source Code Vote up 4 votes
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    autowireCapableBeanFactory = applicationContext.getAutowireCapableBeanFactory();
}
 
Example 14
Project: minsx-java-example   File: AppConfig.java   View Source Code Vote up 4 votes
private void registerBeans(ApplicationContext applicationContext) throws BeansException {
    DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) applicationContext.getAutowireCapableBeanFactory();
    BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(getUserRepositoryProxy().getClass());
    defaultListableBeanFactory.registerBeanDefinition("userRepository", beanDefinitionBuilder.getBeanDefinition());
}
 
Example 15
Project: springboot-quartz   File: AutowiringSpringBeanJobFactory.java   View Source Code Vote up 4 votes
@Override
public void setApplicationContext(final ApplicationContext context) {
    beanFactory = context.getAutowireCapableBeanFactory();
}
 
Example 16
Project: springmock   File: BeanDefinitionFinder.java   View Source Code Vote up 4 votes
public BeanDefinitionFinder(ApplicationContext applicationContext, DoubleRegistry doubleRegistry) {
	this(
			(ConfigurableListableBeanFactory) applicationContext.getAutowireCapableBeanFactory(),
			doubleRegistry);
}
 
Example 17
Project: taskana   File: RestApplication.java   View Source Code Vote up 2 votes
/**
 * Needed for injection into jackson deserilizer.
 *
 * @param context
 * @return
 */
@Bean
public HandlerInstantiator handlerInstantiator(ApplicationContext context) {
    return new SpringHandlerInstantiator(context.getAutowireCapableBeanFactory());
}
 
Example 18
Project: spring-boot-starter-quartz   File: AutowiringSpringBeanJobFactory.java   View Source Code Vote up 2 votes
/**
 * Constructor that takes an auto wire capable bean spring bean factory.
 * @param context
 * 				auto wire capable bean spring bean factory
 */
@Override
public void setApplicationContext(final ApplicationContext context) {
	beanFactory = context.getAutowireCapableBeanFactory();
}