org.springframework.context.ConfigurableApplicationContext.getBean()

Here are the examples of the java api org.springframework.context.ConfigurableApplicationContext.getBean() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

506 Examples 7

19 View Source File : SpringContextUtils.java
License : Apache License 2.0
Project Creator : zifangsky

/**
 * 根据bean的名称获取bean
 */
public static Object getBeanByName(String name) {
    return applicationContext.getBean(name);
}

19 View Source File : SpringContextUtils.java
License : Apache License 2.0
Project Creator : zifangsky

/**
 * 根据bean的clreplaced来查找对象
 */
public static <T> T getBeanByClreplaced(Clreplaced<T> clazz) {
    return applicationContext.getBean(clazz);
}

19 View Source File : ContextUtil.java
License : MIT License
Project Creator : wolforest

public static <T> T getBean(Clreplaced<T> c) {
    if (!isInit) {
        throw new WolfException("BeanUtil does not init");
    }
    return applicationContext.getBean(c);
}

19 View Source File : ContextUtil.java
License : MIT License
Project Creator : wolforest

public static <T> T getBean(String clreplacedName, Clreplaced<T> t) {
    if (!isInit) {
        throw new WolfException("BeanUtil does not init");
    }
    return applicationContext.getBean(clreplacedName, t);
}

19 View Source File : ContextUtil.java
License : MIT License
Project Creator : wolforest

public static Object getBean(String clreplacedName) {
    if (!isInit) {
        throw new WolfException("BeanUtil does not init");
    }
    return applicationContext.getBean(clreplacedName);
}

19 View Source File : Spr10546Tests.java
License : MIT License
Project Creator : Vip-Augus

private void replacedertLoadsMyBean(Clreplaced<?>... annotatedClreplacedes) {
    context = new AnnotationConfigApplicationContext(annotatedClreplacedes);
    replacedertThat(context.getBean("myBean", String.clreplaced), equalTo("myBean"));
}

19 View Source File : SpringBeanUtils.java
License : Apache License 2.0
Project Creator : sunshinelyz

/**
 * acquire spring bean.
 *
 * @param type type
 * @param <T>  clreplaced
 * @return bean
 */
public <T> T getBean(final Clreplaced<T> type) {
    replacedertUtils.notNull(type);
    return cfgContext.getBean(type);
}

19 View Source File : RoutingFunctionTests.java
License : Apache License 2.0
Project Creator : spring-cloud

private FunctionCatalog configureCatalog() {
    context = new SpringApplicationBuilder(RoutingFunctionConfiguration.clreplaced).run("--logging.level.org.springframework.cloud.function=DEBUG", "--spring.cloud.function.routing.enabled=true");
    return context.getBean(FunctionCatalog.clreplaced);
}

19 View Source File : Spr10546Tests.java
License : Apache License 2.0
Project Creator : SourceHot

private void replacedertLoadsMyBean(Clreplaced<?>... annotatedClreplacedes) {
    context = new AnnotationConfigApplicationContext(annotatedClreplacedes);
    replacedertThat(context.getBean("myBean", String.clreplaced)).isEqualTo("myBean");
}

19 View Source File : RegistryApplication.java
License : Apache License 2.0
Project Creator : sofastack

public static void stop() {
    if (sessionApplicationContext != null) {
        sessionApplicationContext.getBean("sessionServerBootstrap", SessionServerBootstrap.clreplaced).destroy();
    }
    if (dataApplicationContext != null) {
        dataApplicationContext.getBean("dataServerBootstrap", DataServerBootstrap.clreplaced).destroy();
    }
    if (metaApplicationContext != null) {
        metaApplicationContext.getBean("metaServerBootstrap", MetaServerBootstrap.clreplaced).destroy();
    }
}

19 View Source File : TestBase.java
License : Apache License 2.0
Project Creator : snowdrop

protected <T> T getBean(Clreplaced<T> beanClreplaced) {
    return context.getBean(beanClreplaced);
}

19 View Source File : MessageQueueConsumerBeanPostProcessor.java
License : Apache License 2.0
Project Creator : otto-de

private MessageReceiverEndpoint matchingMessageQueueReceiverEndpointFor(final MessageQueueConsumer annotation) {
    return applicationContext.getBean(annotation.endpointName(), MessageQueueReceiverEndpoint.clreplaced);
}

19 View Source File : MessageLogConsumerBeanPostProcessor.java
License : Apache License 2.0
Project Creator : otto-de

private MessageReceiverEndpoint matchingMessageLogReceiverEndpointFor(final MessageLogConsumer annotation) {
    return applicationContext.getBean(annotation.endpointName(), MessageLogReceiverEndpoint.clreplaced);
}

19 View Source File : EventSourceConsumerBeanPostProcessor.java
License : Apache License 2.0
Project Creator : otto-de

private EventSource matchingEventSourceFor(final EventSourceConsumer annotation) {
    return applicationContext.getBean(annotation.eventSource(), EventSource.clreplaced);
}

19 View Source File : Server.java
License : Apache License 2.0
Project Creator : NationalSecurityAgency

protected static Configuration initializeConfiguration(String[] args) {
    applicationContext = new SpringApplicationBuilder(SpringBootstrap.clreplaced).web(false).run(args);
    return applicationContext.getBean(Configuration.clreplaced);
}

19 View Source File : ContextUtils.java
License : Apache License 2.0
Project Creator : momobaiduren

public static <T> T getBean(Clreplaced<T> type, boolean required) {
    if (type != null && applicationContext != null) {
        if (required) {
            return applicationContext.getBean(type);
        } else {
            if (applicationContext.getBeansOfType(type).size() > 0) {
                return applicationContext.getBean(type);
            }
        }
    }
    return null;
}

19 View Source File : FormApp.java
License : MIT License
Project Creator : jasrodis

@Override
public void init() throws Exception {
    springContext = SpringApplication.run(FormApp.clreplaced);
    FormController controller = springContext.getBean(FormController.clreplaced);
    scene = new Scene(controller.getView());
    scene.getStylesheets().add(CSS_PATH);
}

19 View Source File : ChartApp.java
License : MIT License
Project Creator : jasrodis

@Override
public void init() throws Exception {
    springContext = SpringApplication.run(ChartApp.clreplaced);
    ChartController controller = springContext.getBean(ChartController.clreplaced);
    scene = new Scene(controller.getView());
    scene.getStylesheets().add(CSS_PATH);
}

19 View Source File : BootFxApp.java
License : MIT License
Project Creator : jasrodis

@Override
public void init() throws Exception {
    springContext = SpringApplication.run(BootFxApp.clreplaced);
    BootFxController controller = springContext.getBean(BootFxController.clreplaced);
    scene = new Scene(controller.getView());
    scene.getStylesheets().add(CSS_PATH);
}

19 View Source File : ServerStart.java
License : MIT License
Project Creator : intuit

public void start(String[] args, boolean wait) throws Exception {
    if (wait) {
        try {
            logger.info("attempting to stop server if it is already running");
            new ServerStop().stopServer();
        } catch (Exception e) {
            logger.info("failed to stop server (was probably not up): {}", e.getMessage());
        }
    }
    context = Application.run(args);
    ServerStartedInitializingBean ss = context.getBean(ServerStartedInitializingBean.clreplaced);
    port = ss.getLocalPort();
    logger.info("started server on port: {}", port);
    if (wait) {
        int stopPort = port + 1;
        logger.info("will use stop port as {}", stopPort);
        monitor = new MonitorThread(stopPort, () -> context.close());
        monitor.start();
        monitor.join();
    }
}

19 View Source File : Server.java
License : Apache License 2.0
Project Creator : interledger4j

public int getPort() {
    // Take the port out of the properties...
    // return
    // Optional.ofNullable(this.properties.getProperty(ILP_SERVER_PORT))
    // .map(Integer::new)
    // .orElseGet(() -> {
    if (context != null) {
        return context.getBean(ConnectorServerConfig.clreplaced).getPort();
    } else {
        throw new IllegalStateException("Server not started!");
    }
// });
}

19 View Source File : BeekeeperSchedulerApiaryTest.java
License : Apache License 2.0
Project Creator : ExpediaGroup

private void setupContextMock(boolean defineContext, boolean defineMeterRegistry, boolean defineRunner) {
    BeekeeperSchedulerApiary beekeeperSchedulerApiary = new BeekeeperSchedulerApiary();
    when(contextMock.getBean("compositeMeterRegistry")).thenReturn(defineMeterRegistry ? meterRegistryMock : null);
    when(contextMock.getBean("schedulerApiaryRunner")).thenReturn(defineRunner ? runnerMock : null);
    if (defineContext) {
        beekeeperSchedulerApiary.setApplicationContext(contextMock);
    }
}

19 View Source File : SpringBeanUtils.java
License : Apache License 2.0
Project Creator : dromara

/**
 * acquire spring bean.
 *
 * @param type type
 * @param <T>  clreplaced
 * @return bean
 */
public <T> T getBean(final Clreplaced<T> type) {
    return cfgContext.getBean(type);
}

19 View Source File : SpringBeanUtils.java
License : Apache License 2.0
Project Creator : dromara

/**
 * acquire spring bean.
 *
 * @param <T>  clreplaced
 * @param type type
 * @return bean bean
 */
public <T> T getBean(final Clreplaced<T> type) {
    return cfgContext.getBean(type);
}

19 View Source File : SpringBeanUtils.java
License : GNU Lesser General Public License v3.0
Project Creator : dromara

/**
 * acquire spring bean by bean name and type.
 *
 * @param beanName bean name
 * @param type type
 * @param <T>  clreplaced
 * @return bean
 */
public <T> T getBean(final String beanName, final Clreplaced<T> type) {
    return cfgContext.getBean(beanName, type);
}

19 View Source File : BootShim.java
License : Apache License 2.0
Project Creator : avast

public JLineShellComponent getJLineShellComponent() {
    return ctx.getBean("shell", JLineShellComponent.clreplaced);
}

19 View Source File : WebServer.java
License : MIT License
Project Creator : aergoio

/**
 * Get build service from server.
 *
 * @return build service
 */
public BuildService getBuildService() {
    if (null == applicationContext) {
        return null;
    }
    return applicationContext.getBean(BuildService.clreplaced);
}

18 View Source File : WebContext.java
License : MIT License
Project Creator : yizzuide

/**
 * 注册BeanDefinition
 * @param applicationContext    应用上下文
 * @param name                  bean name
 * @param clazz                 bean clreplaced
 * @param beanDefinition        BeanDefinition
 * @param <T>                   实体类型
 * @return  Bean
 */
public static <T> T registerBean(ConfigurableApplicationContext applicationContext, String name, Clreplaced<T> clazz, BeanDefinition beanDefinition) {
    BeanDefinitionRegistry beanFactory = (BeanDefinitionRegistry) applicationContext.getBeanFactory();
    beanFactory.registerBeanDefinition(name, beanDefinition);
    return applicationContext.getBean(name, clazz);
}

18 View Source File : Application.java
License : MIT License
Project Creator : Yirendai

public static void main(final String... args) {
    final ConfigurableApplicationContext context = SpringApplication.run(Application.clreplaced, args);
    context.getBean(Application.clreplaced).run();
}

18 View Source File : NettySpringApplication.java
License : Apache License 2.0
Project Creator : yetel

public static void main(String[] args) {
    ConfigurableApplicationContext ctx = SpringApplication.run(NettySpringApplication.clreplaced, args);
    NettyServer nettyServer = ctx.getBean(NettyServer.clreplaced);
    nettyServer.start();
}

18 View Source File : SpringBootStarterExample.java
License : Apache License 2.0
Project Creator : Xlinlin

private static CommonService getCommonService(final ConfigurableApplicationContext applicationContext) {
    return applicationContext.getBean(SpringPojoServiceImpl.clreplaced);
}

18 View Source File : SpringbootDubboClientApplication.java
License : Apache License 2.0
Project Creator : WinterChenS

public static void main(String[] args) {
    // 程序启动入口
    // 启动嵌入式的 Tomcat 并初始化 Spring 环境及其各 Spring 组件
    ConfigurableApplicationContext run = SpringApplication.run(SpringbootDubboClientApplication.clreplaced, args);
    UserDubboConsumerService userService = run.getBean(UserDubboConsumerService.clreplaced);
    userService.printUser();
}

18 View Source File : SocketServer.java
License : Apache License 2.0
Project Creator : wangmingco

public static void main(String[] args) {
    ConfigurableApplicationContext context = SpringApplication.run(SocketServer.clreplaced);
    log.info("********************************************************************");
    for (String beanDefinitionName : context.getBeanDefinitionNames()) {
        Object bean = context.getBean(beanDefinitionName);
        String name = bean.getClreplaced().getCanonicalName();
        if (name == null) {
            log.error("找不到类名:{}", beanDefinitionName);
            continue;
        }
        if (!name.contains("wangming")) {
            continue;
        }
        log.info("Find  --> " + beanDefinitionName + " ---  " + bean);
    }
    log.info("********************************************************************");
}

18 View Source File : AnnotationDrivenBeanDefinitionParserTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void asyncPostProcessorExceptionHandlerReference() {
    Object exceptionHandler = context.getBean("testExceptionHandler");
    Object postProcessor = context.getBean(TaskManagementConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME);
    replacedertSame(exceptionHandler, ((Supplier<?>) new DirectFieldAccessor(postProcessor).getPropertyValue("exceptionHandler")).get());
}

18 View Source File : AnnotationDrivenBeanDefinitionParserTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void asyncPostProcessorExecutorReference() {
    Object executor = context.getBean("testExecutor");
    Object postProcessor = context.getBean(TaskManagementConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME);
    replacedertSame(executor, ((Supplier<?>) new DirectFieldAccessor(postProcessor).getPropertyValue("executor")).get());
}

18 View Source File : AnnotationDrivenBeanDefinitionParserTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void scheduledPostProcessorSchedulerReference() {
    Object scheduler = context.getBean("testScheduler");
    Object postProcessor = context.getBean(TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME);
    replacedertSame(scheduler, new DirectFieldAccessor(postProcessor).getPropertyValue("scheduler"));
}

18 View Source File : AnnotationDrivenEventListenerTests.java
License : MIT License
Project Creator : Vip-Augus

private EventCollector getEventCollector(ConfigurableApplicationContext context) {
    return context.getBean(EventCollector.clreplaced);
}

18 View Source File : Spr12636Tests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void orderOnImplementation() {
    this.context = new AnnotationConfigApplicationContext(UserServiceTwo.clreplaced, UserServiceOne.clreplaced, UserServiceCollector.clreplaced);
    UserServiceCollector bean = this.context.getBean(UserServiceCollector.clreplaced);
    replacedertSame(context.getBean("serviceOne", UserService.clreplaced), bean.userServices.get(0));
    replacedertSame(context.getBean("serviceTwo", UserService.clreplaced), bean.userServices.get(1));
}

18 View Source File : AnnotationDrivenBeanDefinitionParserTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
@SuppressWarnings("rawtypes")
public void asyncPostProcessorExecutorReference() {
    Object executor = context.getBean("testExecutor");
    Object aspect = context.getBean(TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME);
    replacedertSame(executor, ((Supplier) new DirectFieldAccessor(aspect).getPropertyValue("defaultExecutor")).get());
}

18 View Source File : AnnotationDrivenBeanDefinitionParserTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
@SuppressWarnings("rawtypes")
public void asyncPostProcessorExceptionHandlerReference() {
    Object exceptionHandler = context.getBean("testExceptionHandler");
    Object aspect = context.getBean(TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME);
    replacedertSame(exceptionHandler, ((Supplier) new DirectFieldAccessor(aspect).getPropertyValue("exceptionHandler")).get());
}

18 View Source File : ConsumerApplication.java
License : Apache License 2.0
Project Creator : ukihsoroy

public static void main(String[] args) {
    ConfigurableApplicationContext run = SpringApplication.run(ConsumerApplication.clreplaced, args);
    UserService userService = run.getBean(UserService.clreplaced);
    _LOGGER.info("UserService.getUser Return: {}", userService.getUser().toString());
}

18 View Source File : ConsumerApplication.java
License : Apache License 2.0
Project Creator : ukihsoroy

public static void main(String[] args) {
    ConfigurableApplicationContext run = SpringApplication.run(ConsumerApplication.clreplaced, args);
    UserService userService = run.getBean(UserService.clreplaced);
    _LOGGER.info("UserService.getUserName Return: {}", userService.getUserName());
}

18 View Source File : ChaosEngine.java
License : Apache License 2.0
Project Creator : ThalesGroup

public static void restart() {
    ApplicationArguments args = context.getBean(ApplicationArguments.clreplaced);
    Thread thread = new Thread(() -> {
        context.close();
        SpringApplication app;
        app = new SpringApplication(ChaosEngine.clreplaced);
        app.setBannerMode(Banner.Mode.OFF);
        context = app.run(args.getSourceArgs());
    });
    thread.setDaemon(false);
    thread.start();
}

18 View Source File : AuthorizationServerApplication.java
License : MIT License
Project Creator : tadeucruz

public static void main(String[] args) {
    ConfigurableApplicationContext ctx = SpringApplication.run(AuthorizationServerApplication.clreplaced, args);
    ctx.getBean(CreateDefaultUserListener.clreplaced);
}

18 View Source File : SpringBuilder.java
License : Apache License 2.0
Project Creator : T-baby

public static <T> T getBean(Clreplaced<T> clazz) {
    ConfigurableApplicationContext context = getContext();
    if (context != null) {
        return context.getBean(clazz);
    }
    return null;
}

18 View Source File : MainApplication.java
License : Apache License 2.0
Project Creator : sum1re

@Override
public void start(Stage stage) throws IOException {
    context.publishEvent(new StageEvent(stage));
    DataUtil dataUtil = context.getBean(DataUtil.clreplaced);
    dataUtil.dealOldData();
    AppHolder appHolder = context.getBean(AppHolder.clreplaced);
    appHolder.setHostServices(getHostServices());
    notifyPreloader(new Preloader.StateChangeNotification(BEFORE_START));
}

18 View Source File : S1pKafkaApplication.java
License : Apache License 2.0
Project Creator : SpringOnePlatform2016

public static void main(String[] args) {
    ConfigurableApplicationContext context = new SpringApplicationBuilder(S1pKafkaApplication.clreplaced).web(false).run(args);
    TestBean testBean = context.getBean(TestBean.clreplaced);
    testBean.send("foo");
}

18 View Source File : UserRepositoryTest.java
License : Apache License 2.0
Project Creator : spring-projects-experimental

@Test
public void testFindOne() {
    var repository = context.getBean(UserRepository.clreplaced);
    var expected = new User();
    expected.setLogin("sdeleuze");
    expected.setFirstname("Sébastien");
    expected.setLastname("Deleuze");
    replacedertEquals(expected, repository.findOne("sdeleuze").block());
}

18 View Source File : UserRepositoryTest.java
License : Apache License 2.0
Project Creator : spring-projects-experimental

@Test
public void count() {
    var repository = context.getBean(UserRepository.clreplaced);
    replacedertEquals(3, repository.count().block());
}

18 View Source File : FeignHttpClient5ConfigurationTests.java
License : Apache License 2.0
Project Creator : spring-cloud

private static void verifyHc4BeansAvailable(ConfigurableApplicationContext context) {
    org.apache.http.impl.client.CloseableHttpClient httpClient4 = context.getBean(org.apache.http.impl.client.CloseableHttpClient.clreplaced);
    replacedertThat(httpClient4).isNotNull();
    org.apache.http.conn.HttpClientConnectionManager connectionManager4 = context.getBean(org.apache.http.conn.HttpClientConnectionManager.clreplaced);
    replacedertThat(connectionManager4).isInstanceOf(org.apache.http.impl.conn.PoolingHttpClientConnectionManager.clreplaced);
    Client client = context.getBean(Client.clreplaced);
    replacedertThat(client).isInstanceOf(ApacheHttpClient.clreplaced);
}

See More Examples