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

x33g5p2x  于2022-01-15 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(99)

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

AnnotationConfigApplicationContext.getAutowireCapableBeanFactory介绍

暂无

代码示例

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

private void loadContext(Class<?> clazz) {
  AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(clazz);
  context.getAutowireCapableBeanFactory().autowireBean(this);
}

代码示例来源:origin: Atmosphere/atmosphere-extensions

@Override
public <T, U extends T> U newClassInstance(Class<T> classType,
                      Class<U> classToInstantiate)
    throws InstantiationException, IllegalAccessException {
  if (preventSpringInjection && excludedFromInjection.contains(classType)) {
    logger.trace("Excluded from injection {}", classToInstantiate.getName());
    return classToInstantiate.newInstance();
  }
  String name = classToInstantiate.getSimpleName();
  if (!context.containsBeanDefinition(Introspector.decapitalize(name))) {
    context.register(classToInstantiate);
  }
  U t = context.getAutowireCapableBeanFactory().createBean(classToInstantiate);
  if (t == null) {
    logger.info("Unable to find {}. Creating the object directly."
        + classToInstantiate.getName());
    return classToInstantiate.newInstance();
  }
  return t;
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-netflix-ribbon

static <C> C instantiateWithConfig(AnnotationConfigApplicationContext context,
                  Class<C> clazz, IClientConfig config) {
  C result = null;
  
  try {
    Constructor<C> constructor = clazz.getConstructor(IClientConfig.class);
    result = constructor.newInstance(config);
  } catch (Throwable e) {
    // Ignored
  }
  
  if (result == null) {
    result = BeanUtils.instantiate(clazz);
    
    if (result instanceof IClientConfigAware) {
      ((IClientConfigAware) result).initWithNiwsConfig(config);
    }
    
    if (context != null) {
      context.getAutowireCapableBeanFactory().autowireBean(result);
    }
  }
  
  return result;
}

代码示例来源:origin: amoAHCP/spring-vertx-ext

/**
 * Initialize a Spring Context for given Verticle instance. A Verticle MUST be annotated with {@link SpringVerticle}
 * @param verticle The Verticle Instance where to start the Spring Context
 */
public static void initSpring(AbstractVerticle verticle) {
  final Class<?> currentVerticleClass = verticle.getClass();
  final Vertx vertx = verticle.getVertx();
  if(!currentVerticleClass.isAnnotationPresent(SpringVerticle.class)) {
    throw new InvalidParameterException("no @SpringVerticle annotation found");
  }
  final SpringVerticle annotation = currentVerticleClass.getAnnotation(SpringVerticle.class);
  final Class<?> springConfigClass = annotation.springConfig();
  // Create the parent context
  final GenericApplicationContext genericApplicationContext = getGenericApplicationContext(
    vertx.getClass().getClassLoader());
  // 1. Create a new context for each verticle and use the specified spring configuration class if possible
  AnnotationConfigApplicationContext annotationConfigApplicationContext = getAnnotationConfigApplicationContext(
    springConfigClass, genericApplicationContext);
  // 2. Register the Vertx instance as a singleton in spring context
  annotationConfigApplicationContext.getBeanFactory().registerSingleton(vertx.getClass().getSimpleName(), vertx);
  // 3. Register a bean definition for this verticle
  annotationConfigApplicationContext.getBeanFactory().registerSingleton(verticle.getClass().getSimpleName(), verticle);
  // 4. Add a bean factory post processor to avoid configuration issues
  addPostprocessorAndUpdateContext(currentVerticleClass, annotationConfigApplicationContext);
  // 5. perform autowiring
  annotationConfigApplicationContext.getAutowireCapableBeanFactory().autowireBean(verticle);
}

代码示例来源:origin: io.hekate/hekate-spring

@Override
public void configure(ConfigurationContext ctx) {
  // Application context for autowiring.
  AnnotationConfigApplicationContext autowireCtx = new AnnotationConfigApplicationContext() {
    @Override
    public String toString() {
      return SpringInjectionService.class.getSimpleName() + "Context";
    }
  };
  // Expose services for autowiring.
  ConfigurableListableBeanFactory factory = autowireCtx.getBeanFactory();
  uniqueServices(ctx).forEach(service -> {
    factory.registerResolvableDependency(service.getClass(), service);
    for (Class<?> type : service.getClass().getInterfaces()) {
      factory.registerResolvableDependency(type, service);
    }
  });
  autowireCtx.refresh();
  autowireCtx.setParent(parentCtx);
  autowire = autowireCtx.getAutowireCapableBeanFactory();
}

代码示例来源:origin: DSpace/DSpace

line.hasOption('v'));
applicationContext.getAutowireCapableBeanFactory().autowireBean(indexer);
applicationContext.getAutowireCapableBeanFactory().autowireBean(indexer);

代码示例来源:origin: GoMint/GoMint

/**
 * Handles a new incoming connection.
 *
 * @param newConnection The new incoming connection
 */
private void handleNewConnection(Connection newConnection) {
  this.context.registerBean("network.newConnection.raknet", Connection.class, () -> newConnection);
  this.context.registerBean("network.newConnection.tcp", ConnectionHandler.class, () -> null);
  PlayerConnection playerConnection = this.context.getAutowireCapableBeanFactory().getBean(PlayerConnection.class);
  this.incomingConnections.add(playerConnection);
  this.context.removeBeanDefinition("network.newConnection.raknet");
  this.context.removeBeanDefinition("network.newConnection.tcp");
}

代码示例来源:origin: GoMint/GoMint

public void constructGenerator(Class<? extends ChunkGenerator> generator, GeneratorContext context) throws
  WorldCreateException {
  try {
    this.chunkGenerator = generator.getConstructor(World.class, GeneratorContext.class).newInstance(this, context);
    this.server.getContext().getAutowireCapableBeanFactory().autowireBean(this.chunkGenerator);
  } catch (NoSuchMethodException e) {
    throw new WorldCreateException("The given generator does not provide a (World, GeneratorContext) constructor");
  } catch (IllegalAccessException e) {
    throw new WorldCreateException("The given generator can't be constructed. Be sure the (World, GeneratorContext) constructor is public");
  } catch (InstantiationException e) {
    throw new WorldCreateException("The generator given is either an abstracted class or some kind of interface");
  } catch (InvocationTargetException e) {
    throw new WorldCreateException("The constructor of the generator has thrown this exception", e);
  }
}

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

@SuppressWarnings("resource")
@Before
public void setUp()
{
  ThreadDelegatedScope.SCOPE.changeScope(null);
  new AnnotationConfigApplicationContext(ThreadDelegatedScopeConfiguration.class, ScopedObject.Config.class)
      .getAutowireCapableBeanFactory().autowireBean(this);
  Assert.assertNotNull(context);
  unwrappedExecutor = new ThreadPoolExecutor(5, 5, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
  Assert.assertFalse(unwrappedExecutor.isShutdown());
  Assert.assertFalse(unwrappedExecutor.isTerminated());
}

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

@SuppressWarnings("resource")
@Before
public void setUp()
{
  ThreadDelegatedScope.SCOPE.changeScope(null);
  new AnnotationConfigApplicationContext(ThreadDelegatedScopeConfiguration.class, ScopedObject.Config.class)
      .getAutowireCapableBeanFactory().autowireBean(this);
  Assert.assertNotNull(context);
  unwrappedExecutor = new ThreadPoolExecutor(5, 5, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
  Assert.assertFalse(unwrappedExecutor.isShutdown());
  Assert.assertFalse(unwrappedExecutor.isTerminated());
}

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

@Test
public void test() {
  final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfiguration.class);
  final BeanFactory factory = context.getAutowireCapableBeanFactory();
  final String key = "com.opentable.metrics.MetricAnnotationTest.TestConfiguration.Annotated.timed";
  final MetricRegistry metricRegistry = factory.getBean(MetricRegistry.class);
  final Map<String, Metric> metrics = metricRegistry.getMetrics();
  Assert.assertNotNull(metrics);
  Assert.assertFalse(metrics.isEmpty());
  Assert.assertTrue(metrics.containsKey(key));
  final Timer timer = (Timer) metrics.get(key);
  Assert.assertEquals(timer.getCount(), 0);
  factory.getBean(TestConfiguration.Annotated.class).timed();
  factory.getBean(TestConfiguration.Annotated.class).timed();
  Assert.assertEquals(timer.getCount(), 2);
  context.close();
}

代码示例来源:origin: GoMint/GoMint

this.context.registerBean("network.newConnection.tcp", ConnectionHandler.class, () -> connectionHandler);
PlayerConnection playerConnection = this.context.getAutowireCapableBeanFactory().getBean(PlayerConnection.class);
playerConnection.setTcpId(idCounter.incrementAndGet());

代码示例来源:origin: GoMint/GoMint

String host = args.has("lh") ? (String) args.valueOf("lh") : this.serverConfig.getListener().getIp();
this.networkManager = this.context.getAutowireCapableBeanFactory().createBean(NetworkManager.class);
if (!this.initNetworking(host, port)) {
  this.internalShutdown();

代码示例来源:origin: GoMint/GoMint

TileEntity tileEntityInstance = instance.createTileEntity( new NBTTagCompound( "" ) );
if ( tileEntityInstance != null ) {
  this.world.getServer().getContext().getAutowireCapableBeanFactory().autowireBean( tileEntityInstance );
  instance.setTileEntity( tileEntityInstance );
  worldAdapter.storeTileEntity( pos, tileEntityInstance );

代码示例来源:origin: GoMint/GoMint

this.world.getServer().getContext().getAutowireCapableBeanFactory().autowireBean( tileEntityInstance );
instance.setTileEntity( tileEntityInstance );
worldAdapter.storeTileEntity( pos, tileEntityInstance );

相关文章

微信公众号

最新文章

更多

AnnotationConfigApplicationContext类方法