org.springframework.context.ConfigurableApplicationContext.getAutowireCapableBeanFactory()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中org.springframework.context.ConfigurableApplicationContext.getAutowireCapableBeanFactory()方法的一些代码示例,展示了ConfigurableApplicationContext.getAutowireCapableBeanFactory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ConfigurableApplicationContext.getAutowireCapableBeanFactory()方法的具体详情如下:
包路径:org.springframework.context.ConfigurableApplicationContext
类名称:ConfigurableApplicationContext
方法名:getAutowireCapableBeanFactory

ConfigurableApplicationContext.getAutowireCapableBeanFactory介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Before
public void setup() {
  if (applicationContext == null) {
    applicationContext = new ClassPathXmlApplicationContext(getConfigLocations());
  }
  applicationContext.getAutowireCapableBeanFactory().autowireBean(this);
  if (this.transactionManager != null && this.transactionDefinition != null) {
    startNewTransaction();
  }
}

代码示例来源:origin: spring-projects/spring-batch

context.getAutowireCapableBeanFactory().autowireBeanProperties(this,
    AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);

代码示例来源:origin: spring-projects/spring-integration

public EventDrivenConsumer buildContext(String routerDef) {
  appContext = TestXmlApplicationContextHelper.getTestAppContext(channelConfig + routerDef);
  appContext.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
  EventDrivenConsumer consumer = (EventDrivenConsumer) appContext.getBean("router");
  consumer.start();
  return consumer;
}

代码示例来源:origin: NationalSecurityAgency/datawave

@Override
public AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException {
  lock.readLock().lock();
  try {
    return configurableApplicationContext.getAutowireCapableBeanFactory();
  } finally {
    lock.readLock().unlock();
  }
}

代码示例来源:origin: hernad/easyrec

public void setSlopeoneGenerator(final SlopeOneGenerator slopeOneGenerator) {
  this.slopeOneGenerator = slopeOneGenerator;
  super.context.getAutowireCapableBeanFactory()
      .autowireBeanProperties(slopeOneGenerator, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
}

代码示例来源:origin: hernad/easyrec

@SuppressWarnings({"UnusedDeclaration"})
public void setItemItemGenerator(final ItemItemGenerator itemItemGenerator) {
  this.itemItemGenerator = itemItemGenerator;
  super.context.getAutowireCapableBeanFactory()
      .autowireBeanProperties(itemItemGenerator, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
}

代码示例来源:origin: org.echocat.jomon.spring/testing

protected void autowire(@Nonnull ConfigurableApplicationContext applicationContext, @Nonnull Object bean) {
  final AutowireCapableBeanFactory autowireCapableBeanFactory = applicationContext.getAutowireCapableBeanFactory();
  autowireCapableBeanFactory.autowireBean(bean);
}

代码示例来源:origin: fnproject/fdk-java

/**
 * A common pattern is to call this function from within a Configuration method of
 * a {@link org.springframework.beans.factory.annotation.Configurable} function.
 *
 * @param configClass The class which defines your Spring Cloud Function @Beans
 */
public SpringCloudFunctionInvoker(Class<?> configClass) {
  SpringApplicationBuilder builder = new SpringApplicationBuilder(configClass);
  applicationContext = builder.web(false).run();
  loader = applicationContext.getAutowireCapableBeanFactory().createBean(SpringCloudFunctionLoader.class);
  loader.loadFunction();
}

代码示例来源:origin: org.springframework.data/spring-yarn-core

/**
 * Gets the Application Context.
 *
 * @param configLocation the context config location
 * @param parent the parent context
 * @return the configured context
 */
protected ConfigurableApplicationContext getChildApplicationContext(
    String configLocation, ConfigurableApplicationContext parent) {
  if (configLocation != null) {
    ConfigurableApplicationContext context =
        new ClassPathXmlApplicationContext(new String[]{configLocation}, parent);
    context.getAutowireCapableBeanFactory().autowireBeanProperties(this,
        AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
    return context;
  } else {
    return null;
  }
}

代码示例来源:origin: org.springframework.data/spring-yarn-core

/**
 * Gets the Application Context.
 *
 * @param configLocation the context config location
 * @return the configured context
 */
protected ConfigurableApplicationContext getApplicationContext(String configLocation) {
  ConfigurableApplicationContext context;
  if (ClassUtils.isPresent(configLocation, getClass().getClassLoader())) {
    Class<?> clazz = ClassUtils.resolveClassName(configLocation, getClass().getClassLoader());
    context = new AnnotationConfigApplicationContext(clazz);
  } else {
    context = new ClassPathXmlApplicationContext(configLocation);
  }
  context.getAutowireCapableBeanFactory().autowireBeanProperties(this,
      AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
  return context;
}

代码示例来源:origin: stackoverflow.com

ConfigurableApplicationContext ctx = SpringApplication.run(ProxyApplication.class, args);
 BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ctx.getAutowireCapableBeanFactory();
 for(String beanName : ctx.getBeanDefinitionNames()){
   System.out.println(beanName);
   registry.removeBeanDefinition(beanName);
 }

代码示例来源:origin: org.grails/grails-datastore-gorm

protected void autowireBeanProperties(final Object entity) {
  ConfigurableApplicationContext applicationContext = datastore.getApplicationContext();
  if(applicationContext != null) {
    applicationContext.getAutowireCapableBeanFactory().autowireBeanProperties(
        entity, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
  }
}

代码示例来源:origin: org.tuxdevelop/spring-batch-lightmin-core-configuration

/**
 * unregisters a bean of the current application context
 *
 * @param beanName name of the bean, which should be destroyed on current application context
 * @throws NoSuchBeanDefinitionException if the context does not contain a bean with the given name
 */
public void unregisterBean(final String beanName) {
  final BeanDefinitionRegistry factory = (BeanDefinitionRegistry) context.getAutowireCapableBeanFactory();
  if (factory.containsBeanDefinition(beanName)) {
    ((DefaultListableBeanFactory) factory).destroySingleton(beanName);
    factory.removeBeanDefinition(beanName);
  } else {
    throw new NoSuchBeanDefinitionException(
        "No Bean definition exists for bean name: " + beanName);
  }
}

代码示例来源:origin: tuxdevelop/spring-batch-lightmin

/**
 * unregisters a bean of the current application context
 *
 * @param beanName name of the bean, which should be destroyed on current application context
 * @throws NoSuchBeanDefinitionException if the context does not contain a bean with the given name
 */
public void unregisterBean(final String beanName) {
  final BeanDefinitionRegistry factory = (BeanDefinitionRegistry) context.getAutowireCapableBeanFactory();
  if (factory.containsBeanDefinition(beanName)) {
    ((DefaultListableBeanFactory) factory).destroySingleton(beanName);
    factory.removeBeanDefinition(beanName);
  } else {
    throw new NoSuchBeanDefinitionException(
        "No Bean definition exists for bean name: " + beanName);
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-function

@SuppressWarnings("unchecked")
protected void initialize() {
  if (!this.initialized.compareAndSet(false, true)) {
    return;
  }
  logger.info("Initializing: " + configurationClass);
  SpringApplication builder = springApplication();
  ConfigurableApplicationContext context = builder.run();
  context.getAutowireCapableBeanFactory().autowireBean(this);
  String name = context.getEnvironment().getProperty("function.name");
  if (name == null) {
    name = "function";
  }
  if (this.catalog == null) {
    if (context.containsBean(name)) {
      this.function = context.getBean(name, Function.class);
    }
  }
  else {
    Set<String> functionNames = this.catalog.getNames(Function.class);
    if (functionNames.size() == 1) {
      this.function = this.catalog.lookup(Function.class,
          functionNames.iterator().next());
    }
    else {
      this.function = this.catalog.lookup(Function.class, name);
    }
  }
  this.context = context;
}

代码示例来源:origin: com.opentable.components/otj-server-jaxrs

private ConfigurableApplicationContext runServer(final String staticPath) {
  final Map<String, Object> props;
  if (staticPath == null) {
    props = Collections.emptyMap();
  } else {
    props = Collections.singletonMap("ot.httpserver.static-path", staticPath);
  }
  final ConfigurableApplicationContext ctx = OTApplication.run(TestServer.class, new String[]{}, props);
  ctx.getAutowireCapableBeanFactory().autowireBean(this);
  return ctx;
}

代码示例来源:origin: at.researchstudio.sat/won-bot

public static void main(String[] args) throws Exception {
 if (args.length != 1){
  System.err.println("arguments: [bot class name]");
  System.exit(1);
 }
 String botClass = args[0];
 SpringApplication app = new SpringApplication(
     new Object[]{"classpath:/spring/app/botRunner.xml"}
 );
 app.setWebEnvironment(false);
 ConfigurableApplicationContext applicationContext =  app.run(args);
 Bot bot = null;
 //create a bot instance and auto-wire it
 AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
 bot = (Bot) beanFactory.autowire(Class.forName(botClass), AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
 Object botBean = beanFactory.initializeBean(bot, "theBot");
 bot = (Bot) botBean;
 //the bot also needs a trigger so its act() method is called regularly.
 // (there is no trigger bean in the context)
 if (bot instanceof TriggeredBot){
  PeriodicTrigger trigger = new PeriodicTrigger(5000, TimeUnit.MILLISECONDS);
  trigger.setInitialDelay(1000);
  ((TriggeredBot) bot).setTrigger(trigger);
 }
 BotManager botManager = (BotManager) applicationContext.getBean("botManager");
 //adding the bot to the bot manager will cause it to be initialized.
 //at that point, the trigger starts.
 botManager.addBot(bot);
}

代码示例来源:origin: com.opentable.components/otj-metrics-core

app.run().getAutowireCapableBeanFactory().autowireBean(this);
if (reporter == null) {
  return null;

代码示例来源:origin: com.opentable.components/otj-server-core

@Before
public void before() {
  Assert.assertNull(ctx);
  ctx = OTApplication.run(Config.class, new String[]{}, ImmutableMap.of("test.a", "3"),
      builder -> builder.web(WebApplicationType.NONE));
  ctx.getAutowireCapableBeanFactory().autowireBean(this);
}

代码示例来源:origin: com.opentable.components/otj-executors

@Test
  public void testThreadPool() throws Exception
  {
    final ExecutorService service = new ThreadPoolBuilder("test").enableTimingWrapper(new MetricRegistry()).build();
    final Thread currentThread = Thread.currentThread();
    try (final ConfigurableApplicationContext context =
        new AnnotationConfigApplicationContext(ThreadDelegatedScopeConfiguration.class, ScopedObject.Config.class)) {
      final BeanFactory factory = context.getAutowireCapableBeanFactory();
      final Object threadDelegatedObject = factory.getBean(ScopedObject.class);

      Future<Boolean> future = service.submit(() -> {
        assertTrue(threadDelegatedObject == factory.getBean(ScopedObject.class));
        return currentThread == Thread.currentThread();
      });

      assertFalse("must not be on same thread", future.get());

      OTExecutors.shutdownAndAwaitTermination(service, shutdownTimeout);

      assertTrue(service.isShutdown());
      assertTrue(service.isTerminated());
    }
  }
}

相关文章

微信公众号

最新文章

更多

ConfigurableApplicationContext类方法