org.springframework.context.ConfigurableApplicationContext.getBeanFactory()

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

83 Examples 7

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

/**
 * 获取BeanFactory对象
 */
public static BeanFactory getBeanFactory() {
    return applicationContext.getBeanFactory();
}

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

/**
 * register bean in spring ioc.
 *
 * @param beanName bean name
 * @param obj      bean
 */
public void registerBean(final String beanName, final Object obj) {
    replacedertUtils.notNull(beanName);
    replacedertUtils.notNull(obj);
    cfgContext.getBeanFactory().registerSingleton(beanName, obj);
}

@Override
public ConfigurableListableBeanFactory getBeanFactory() {
    lock.readLock().lock();
    try {
        return configurableApplicationContext.getBeanFactory();
    } finally {
        lock.readLock().unlock();
    }
}

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

/**
 * register bean in spring ioc.
 * @param beanName bean name
 * @param obj bean
 */
public void registerBean(final String beanName, final Object obj) {
    cfgContext.getBeanFactory().registerSingleton(beanName, obj);
}

18 View Source File : RestartScopeInitializer.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    applicationContext.getBeanFactory().registerScope("restart", new RestartScope());
}

18 View Source File : FailureAnalyzers.java
License : Apache License 2.0
Project Creator : yuanmabiji

private void preparereplacedyzer(ConfigurableApplicationContext context, Failurereplacedyzer replacedyzer) {
    if (replacedyzer instanceof BeanFactoryAware) {
        ((BeanFactoryAware) replacedyzer).setBeanFactory(context.getBeanFactory());
    }
    if (replacedyzer instanceof EnvironmentAware) {
        ((EnvironmentAware) replacedyzer).setEnvironment(context.getEnvironment());
    }
}

18 View Source File : ContextIdApplicationContextInitializer.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    ContextId contextId = getContextId(applicationContext);
    applicationContext.setId(contextId.getId());
    applicationContext.getBeanFactory().registerSingleton(ContextId.clreplaced.getName(), contextId);
}

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    applicationContext.getBeanFactory().addBeanPostProcessor(GemFireMockObjectsBeanPostProcessor.newInstance());
}

18 View Source File : SpringApplication.java
License : Apache License 2.0
Project Creator : spring-io

/**
 * Apply any relevant post processing the {@link ApplicationContext}. Subclreplacedes can
 * apply additional processing as required.
 * @param context the application context
 */
protected void postProcessApplicationContext(ConfigurableApplicationContext context) {
    if (this.beanNameGenerator != null) {
        context.getBeanFactory().registerSingleton(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR, this.beanNameGenerator);
    }
    if (this.resourceLoader != null) {
        if (context instanceof GenericApplicationContext) {
            ((GenericApplicationContext) context).setResourceLoader(this.resourceLoader);
        }
        if (context instanceof DefaultResourceLoader) {
            ((DefaultResourceLoader) context).setClreplacedLoader(this.resourceLoader.getClreplacedLoader());
        }
    }
}

18 View Source File : SpringApplication.java
License : Apache License 2.0
Project Creator : spring-io

private void prepareContext(ConfigurableApplicationContext context, ConfigurableEnvironment environment, SpringApplicationRunListeners listeners, ApplicationArguments applicationArguments, Banner printedBanner) {
    context.setEnvironment(environment);
    postProcessApplicationContext(context);
    applyInitializers(context);
    listeners.contextPrepared(context);
    if (this.logStartupInfo) {
        logStartupInfo(context.getParent() == null);
        logStartupProfileInfo(context);
    }
    // Add boot specific singleton beans
    context.getBeanFactory().registerSingleton("springApplicationArguments", applicationArguments);
    if (printedBanner != null) {
        context.getBeanFactory().registerSingleton("springBootBanner", printedBanner);
    }
    // Load the sources
    Set<Object> sources = getAllSources();
    replacedert.notEmpty(sources, "Sources must not be empty");
    load(context, sources.toArray(new Object[0]));
    listeners.contextLoaded(context);
}

18 View Source File : WebApiApplictionInitalizer.java
License : Apache License 2.0
Project Creator : spring-avengers

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    applicationContext.getBeanFactory().addBeanPostProcessor(new InstantiationAwareBeanPostProcessorAdapter() {

        @Override
        public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
            if (bean instanceof HandlerMethodResolver) {
                HandlerMethodResolver handlerMethodResolver = (HandlerMethodResolver) bean;
                Field typeResolverField = ReflectionUtils.findField(HandlerMethodResolver.clreplaced, "typeResolver", TypeResolver.clreplaced);
                ReflectionUtils.makeAccessible(typeResolverField);
                TypeResolver typeResolver = (TypeResolver) ReflectionUtils.getField(typeResolverField, handlerMethodResolver);
                return new HandlerMethodResolverWrapper(typeResolver);
            } else {
                return bean;
            }
        }
    });
}

18 View Source File : OpenFeignApplictionInitalizer.java
License : Apache License 2.0
Project Creator : spring-avengers

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    applicationContext.getBeanFactory().registerSingleton("summerErrorAdapterApiResultHandler", new SummerErrorAdapterApiResultHandler());
    applicationContext.getBeanFactory().registerSingleton("summer2ErrorApiResultHandler", new Summer2ErrorApiResultHandler());
    applicationContext.getBeanFactory().addBeanPostProcessor(new InstantiationAwareBeanPostProcessorAdapter() {

        @Override
        public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
            if (bean instanceof Decoder && !(bean instanceof ApiResultDecoder)) {
                Decoder decode = (Decoder) bean;
                return new ApiResultDecoder(decode, applicationContext.getBeansOfType(ApiResultHandler.clreplaced).values().stream().collect(Collectors.toList()));
            } else if (bean instanceof RequestParamMethodArgumentResolver) {
                RequestParamMethodArgumentResolver requestParamMethodArgumentResolver = (RequestParamMethodArgumentResolver) bean;
                Field useDefaultResolution = ReflectionUtils.findField(RequestParamMethodArgumentResolver.clreplaced, "useDefaultResolution", RequestParamMethodArgumentResolver.clreplaced);
                ReflectionUtils.makeAccessible(useDefaultResolution);
                Boolean useDefaultResolutionValue = (Boolean) ReflectionUtils.getField(useDefaultResolution, requestParamMethodArgumentResolver);
                return new RequestParamMethodArgumentResolverExt(useDefaultResolutionValue);
            } else {
                return bean;
            }
        }
    });
}

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    try {
        ClreplacedUtils.forName("com.alibaba.druid.pool.DruidDataSource", this.getClreplaced().getClreplacedLoader());
    } catch (ClreplacedNotFoundException e) {
        return;
    }
    applicationContext.getBeanFactory().addBeanPostProcessor(new InstantiationAwareBeanPostProcessorAdapter() {

        @Override
        public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
            if (bean instanceof DataSourceProperties) {
                DataSourceProperties dataSourceProperties = (DataSourceProperties) bean;
                DruidAndMybatisApplicationContextInitializer.this.rewirteDataSourceProperties(dataSourceProperties);
            } else if (bean instanceof MybatisProperties) {
                MybatisProperties mybatisProperties = (MybatisProperties) bean;
                DruidAndMybatisApplicationContextInitializer.this.rewriteMybatisProperties(mybatisProperties);
            }
            return bean;
        }
    });
}

18 View Source File : VertxWebTestClientContextCustomizerTest.java
License : Apache License 2.0
Project Creator : snowdrop

@Test
public void shouldIgnoreNonRegistryBeanFactory() {
    given(mockContext.getBeanFactory()).willReturn(mockFactory);
    customizer.customizeContext(mockContext, null);
    verifyNoInteractions(mockRegistry);
}

18 View Source File : PowermockClassLoadTest.java
License : Apache License 2.0
Project Creator : powermock

@Test
public void testRest() throws Exception {
    BeanDefinition definition = context.getBeanFactory().getBeanDefinition("powermockClreplacedLoadTest.Config");
    String clreplacedName = definition.getBeanClreplacedName();
    Clreplaced aClreplaced = ClreplacedUtils.forName(clreplacedName, null);
    replacedertThat(aClreplaced).isSameAs(((AbstractBeanDefinition) definition).getBeanClreplaced());
}

18 View Source File : ConditionalSpringBootTestResourceTest.java
License : Apache License 2.0
Project Creator : kiegroup

private void whenStartInstance() {
    ConfigurableApplicationContext applicationContext = mock(ConfigurableApplicationContext.clreplaced);
    lenient().when(applicationContext.getBeanFactory()).thenReturn(beanFactory);
    instance.initialize(applicationContext);
}

18 View Source File : ConditionalSpringBootTestResource.java
License : Apache License 2.0
Project Creator : kiegroup

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    if (condition.isEnabled()) {
        testResource.start();
        updateBeanFactory(applicationContext.getBeanFactory());
        updateContextProperty(applicationContext, getKogitoProperty(), getKogitoPropertyValue());
    }
}

18 View Source File : SpringBeanUtils.java
License : MIT License
Project Creator : keets2012

public void registerBean(String beanName, Object obj) {
    replacedert.notNull(beanName);
    replacedert.notNull(obj);
    cfgContext.getBeanFactory().registerSingleton(beanName, obj);
}

18 View Source File : SystemdSpringApplicationRunListener.java
License : Apache License 2.0
Project Creator : jpmsilva

/**
 * {@inheritDoc}
 */
@Override
public void contextPrepared(ConfigurableApplicationContext context) {
    if (provider != null) {
        provider.state(ApplicationState.CONTEXT_PREPARED);
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        Systemd systemd = Objects.requireNonNull(SYSTEMD, "Systemd must not be null");
        if (!beanFactory.containsSingleton(SYSTEMD_BEAN_NAME)) {
            beanFactory.registerSingleton(SYSTEMD_BEAN_NAME, systemd);
        }
        beanFactory.registerSingleton("systemdNotifyApplicationContextStatusProvider", new SystemdNotifyApplicationContextStatusProvider(systemd, applicationId, context.getId(), beanFactory));
    }
}

18 View Source File : RedisApplicationContextInitializer.java
License : Apache License 2.0
Project Creator : HongZhaoHua

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    applicationContext.getBeanFactory().addBeanPostProcessor(new InstantiationAwareBeanPostProcessorAdapter() {

        @Override
        public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
            if (bean instanceof DiscoveryClient) {
                DiscoveryClient discoveryClient = (DiscoveryClient) bean;
                return new DiscoveryManager(discoveryClient, (object) -> {
                    return true;
                }, (object) -> {
                    return true;
                });
            }
            return bean;
        }
    });
}

18 View Source File : SpringContextHolder.java
License : Apache License 2.0
Project Creator : hiparker

/**
 * 注册Bean对象
 * @param beanName beanName
 * @param bean bean对象
 * @param <T> 泛型
 */
public static <T> boolean registerBean(String beanName, T bean) {
    replacedertContextInjected();
    boolean ret = false;
    ConfigurableApplicationContext context = (ConfigurableApplicationContext) applicationContext;
    if (context != null) {
        try {
            context.getBeanFactory().registerSingleton(beanName, bean);
            ret = true;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    return ret;
}

18 View Source File : DictionaryEditorTest.java
License : Apache License 2.0
Project Creator : eclipse

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    applicationContext.getBeanFactory().registerCustomEditor(Dictionary.clreplaced, PropertiesEditor.clreplaced);
}

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

private void configureApplicationContext(ConfigurableApplicationContext annctx) {
    this.createAndRegisterBeanDefinition(annctx, JLineShellComponent.clreplaced, "shell");
    annctx.getBeanFactory().registerSingleton("commandLine", commandLine);
}

18 View Source File : EruController.java
License : GNU General Public License v3.0
Project Creator : assemblits

private void launchDisplayEditor(Display display) {
    log.info("Starting display builder for '{}'", display.getName());
    List<Node> oldSceneBuilders = centerPaneController.getTablesAnchorPane().getChildren().stream().filter(node -> node instanceof EruSceneBuilder).collect(Collectors.toList());
    centerPaneController.getTablesAnchorPane().getChildren().removeAll(oldSceneBuilders);
    try {
        EruSceneBuilder eruSceneBuilder = applicationContext.getBeanFactory().getBean(EruSceneBuilder.clreplaced);
        eruSceneBuilder.init(display);
        centerPaneController.getTablesAnchorPane().getChildren().add(eruSceneBuilder);
    } catch (FxmlFileReadException e) {
        log.error("Error starting scene builder", e);
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setHeaderText("Error on Eru Scene Builder initialization.");
        alert.setContentText(e.getMessage());
        alert.setContentText(e.getLocalizedMessage());
    }
}

17 View Source File : PropertyMappingContextCustomizer.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedContextConfiguration) {
    if (!this.propertySource.isEmpty()) {
        context.getEnvironment().getPropertySources().addFirst(this.propertySource);
    }
    context.getBeanFactory().registerSingleton(PropertyMappingCheckBeanPostProcessor.clreplaced.getName(), new PropertyMappingCheckBeanPostProcessor());
}

17 View Source File : TypeExcludeFiltersContextCustomizer.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedContextConfiguration) {
    if (!this.filters.isEmpty()) {
        context.getBeanFactory().registerSingleton(EXCLUDE_FILTER_BEAN_NAME, createDelegatingTypeExcludeFilter());
    }
}

17 View Source File : WebTestClientContextCustomizer.java
License : Apache License 2.0
Project Creator : yuanmabiji

private void registerWebTestClient(ConfigurableApplicationContext context) {
    ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    if (beanFactory instanceof BeanDefinitionRegistry) {
        registerWebTestClient((BeanDefinitionRegistry) beanFactory);
    }
}

17 View Source File : TestRestTemplateContextCustomizer.java
License : Apache License 2.0
Project Creator : yuanmabiji

private void registerTestRestTemplate(ConfigurableApplicationContext context) {
    ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    if (beanFactory instanceof BeanDefinitionRegistry) {
        registerTestRestTemplate((BeanDefinitionRegistry) context);
    }
}

17 View Source File : ExcludeFilterContextCustomizer.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedContextConfiguration) {
    context.getBeanFactory().registerSingleton(TestTypeExcludeFilter.clreplaced.getName(), new TestTypeExcludeFilter());
}

17 View Source File : ServerEndpointRegistrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void endpointPerConnection() throws Exception {
    @SuppressWarnings("resource")
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.clreplaced);
    ServerEndpointRegistration registration = new ServerEndpointRegistration("/path", EchoEndpoint.clreplaced);
    registration.setBeanFactory(context.getBeanFactory());
    EchoEndpoint endpoint = registration.getConfigurator().getEndpointInstance(EchoEndpoint.clreplaced);
    replacedertNotNull(endpoint);
}

17 View Source File : BeanCreatingHandlerProviderTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void getHandlerWithBeanFactory() {
    @SuppressWarnings("resource")
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.clreplaced);
    BeanCreatingHandlerProvider<EchoHandler> provider = new BeanCreatingHandlerProvider<>(EchoHandler.clreplaced);
    provider.setBeanFactory(context.getBeanFactory());
    replacedertNotNull(provider.getHandler());
}

17 View Source File : ControllerMethodResolver.java
License : MIT License
Project Creator : Vip-Augus

private static List<HandlerMethodArgumentResolver> initResolvers(ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry adapterRegistry, ConfigurableApplicationContext context, boolean supportDataBinding, List<HttpMessageReader<?>> readers) {
    ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    boolean requestMappingMethod = !readers.isEmpty() && supportDataBinding;
    // Annotation-based...
    List<HandlerMethodArgumentResolver> result = new ArrayList<>();
    result.add(new RequestParamMethodArgumentResolver(beanFactory, adapterRegistry, false));
    result.add(new RequestParamMapMethodArgumentResolver(adapterRegistry));
    result.add(new PathVariableMethodArgumentResolver(beanFactory, adapterRegistry));
    result.add(new PathVariableMapMethodArgumentResolver(adapterRegistry));
    result.add(new MatrixVariableMethodArgumentResolver(beanFactory, adapterRegistry));
    result.add(new MatrixVariableMapMethodArgumentResolver(adapterRegistry));
    if (!readers.isEmpty()) {
        result.add(new RequestBodyMethodArgumentResolver(readers, adapterRegistry));
        result.add(new RequestPartMethodArgumentResolver(readers, adapterRegistry));
    }
    if (supportDataBinding) {
        result.add(new ModelAttributeMethodArgumentResolver(adapterRegistry, false));
    }
    result.add(new RequestHeaderMethodArgumentResolver(beanFactory, adapterRegistry));
    result.add(new RequestHeaderMapMethodArgumentResolver(adapterRegistry));
    result.add(new CookieValueMethodArgumentResolver(beanFactory, adapterRegistry));
    result.add(new ExpressionValueMethodArgumentResolver(beanFactory, adapterRegistry));
    result.add(new SessionAttributeMethodArgumentResolver(beanFactory, adapterRegistry));
    result.add(new RequestAttributeMethodArgumentResolver(beanFactory, adapterRegistry));
    // Type-based...
    if (KotlinDetector.isKotlinPresent()) {
        result.add(new ContinuationHandlerMethodArgumentResolver());
    }
    if (!readers.isEmpty()) {
        result.add(new HttpEnreplacedyMethodArgumentResolver(readers, adapterRegistry));
    }
    result.add(new ModelMethodArgumentResolver(adapterRegistry));
    if (supportDataBinding) {
        result.add(new ErrorsMethodArgumentResolver(adapterRegistry));
    }
    result.add(new ServerWebExchangeMethodArgumentResolver(adapterRegistry));
    result.add(new PrincipalMethodArgumentResolver(adapterRegistry));
    if (requestMappingMethod) {
        result.add(new SessionStatusMethodArgumentResolver());
    }
    result.add(new WebSessionMethodArgumentResolver(adapterRegistry));
    // Custom...
    result.addAll(customResolvers.getCustomResolvers());
    // Catch-all...
    result.add(new RequestParamMethodArgumentResolver(beanFactory, adapterRegistry, true));
    if (supportDataBinding) {
        result.add(new ModelAttributeMethodArgumentResolver(adapterRegistry, true));
    }
    return result;
}

17 View Source File : Spr7167Tests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void test() {
    ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MyConfig.clreplaced);
    replacedertThat("someDependency was not post processed", ctx.getBeanFactory().getBeanDefinition("someDependency").getDescription(), equalTo("post processed by MyPostProcessor"));
    MyConfig config = ctx.getBean(MyConfig.clreplaced);
    replacedertTrue("Config clreplaced was not enhanced", ClreplacedUtils.isCglibProxy(config));
}

17 View Source File : BeanFactoryPostProcessorBootstrap.java
License : MIT License
Project Creator : Vip-Augus

public static void main(String[] args) {
    ConfigurableApplicationContext context = new ClreplacedPathXmlApplicationContext("factory.bean/factory-post-processor.xml");
    BeanFactoryPostProcessor beanFactoryPostProcessor = (BeanFactoryPostProcessor) context.getBean("carPostProcessor");
    beanFactoryPostProcessor.postProcessBeanFactory(context.getBeanFactory());
    // 输出 :Car{maxSpeed=0, brand='*****', price=10000.0},敏感词被替换了
    System.out.println(context.getBean("car"));
    // 硬编码 后处理器执行时间
    BeanFactoryPostProcessor hardCodeBeanFactoryPostProcessor = new HardCodeBeanFactoryPostProcessor();
    context.addBeanFactoryPostProcessor(hardCodeBeanFactoryPostProcessor);
    // 更新上下文
    context.refresh();
    // 输出 :
    // Hard Code BeanFactory Post Processor execute time
    // Car{maxSpeed=0, brand='*****', price=10000.0}
    System.out.println(context.getBean("car"));
}

17 View Source File : FunctionalInstallerListener.java
License : Apache License 2.0
Project Creator : spring-projects-experimental

private boolean isPresent(ConfigurableApplicationContext context) {
    ConfigurableListableBeanFactory beans = InfrastructureUtils.getContext(context.getBeanFactory()).getBeanFactory();
    if (!beans.containsSingleton(MONITOR_NAME)) {
        beans.registerSingleton(MONITOR_NAME, monitor);
        return false;
    }
    return true;
}

17 View Source File : DataRedisContextInitializer.java
License : Apache License 2.0
Project Creator : spring-avengers

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    Environment env = applicationContext.getEnvironment();
    applicationContext.getBeanFactory().addBeanPostProcessor(new InstantiationAwareBeanPostProcessorAdapter() {

        @Override
        public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
            if (bean instanceof RedisTemplate) {
                RedisTemplate redisTemplate = (RedisTemplate) bean;
                // do cache
                redisTemplate.opsForValue();
                redisTemplate.opsForList();
                redisTemplate.opsForSet();
                redisTemplate.opsForZSet();
                redisTemplate.opsForGeo();
                redisTemplate.opsForHash();
                redisTemplate.opsForHyperLogLog();
                createProxyHandlers(redisTemplate);
            }
            return bean;
        }
    });
}

17 View Source File : EurekaApplicationContextInitializer.java
License : Apache License 2.0
Project Creator : spring-avengers

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    ConfigurableEnvironment environment = applicationContext.getEnvironment();
    applicationContext.getBeanFactory().addBeanPostProcessor(new InstantiationAwareBeanPostProcessorAdapter() {

        @Override
        public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
            if (bean instanceof CloudEurekaClient) {
                CloudEurekaClient eurekaClient = (CloudEurekaClient) bean;
                try {
                    Field filedPublisher = ReflectionUtils.findField(CloudEurekaClient.clreplaced, "publisher", ApplicationEventPublisher.clreplaced);
                    ReflectionUtils.makeAccessible(filedPublisher);
                    ApplicationEventPublisher publisher = (ApplicationEventPublisher) ReflectionUtils.getField(filedPublisher, eurekaClient);
                    return new EurekaClientWrapper(eurekaClient, environment, publisher);
                } finally {
                    Method method = ReflectionUtils.findMethod(CloudEurekaClient.clreplaced, "cancelScheduledTasks");
                    ReflectionUtils.makeAccessible(method);
                    ReflectionUtils.invokeMethod(method, eurekaClient);
                    eurekaClient = null;
                }
            } else if (bean instanceof EurekaServiceRegistry) {
                EurekaServiceRegistry eurekaServiceRegistry = (EurekaServiceRegistry) bean;
                return new EurekaServiceRegistryWrapper(eurekaServiceRegistry, environment);
            } else if (bean instanceof EurekaInstanceConfigBean) {
                EurekaInstanceConfigBean instanceConfig = (EurekaInstanceConfigBean) bean;
                instanceConfig.setPreferIpAddress(true);
                return bean;
            } else {
                return bean;
            }
        }
    });
}

17 View Source File : ServerEndpointRegistrationTests.java
License : Apache License 2.0
Project Creator : SourceHot

@Test
public void endpointPerConnection() throws Exception {
    @SuppressWarnings("resource")
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.clreplaced);
    ServerEndpointRegistration registration = new ServerEndpointRegistration("/path", EchoEndpoint.clreplaced);
    registration.setBeanFactory(context.getBeanFactory());
    EchoEndpoint endpoint = registration.getConfigurator().getEndpointInstance(EchoEndpoint.clreplaced);
    replacedertThat(endpoint).isNotNull();
}

17 View Source File : BeanCreatingHandlerProviderTests.java
License : Apache License 2.0
Project Creator : SourceHot

@Test
public void getHandlerWithBeanFactory() {
    @SuppressWarnings("resource")
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.clreplaced);
    BeanCreatingHandlerProvider<EchoHandler> provider = new BeanCreatingHandlerProvider<>(EchoHandler.clreplaced);
    provider.setBeanFactory(context.getBeanFactory());
    replacedertThat(provider.getHandler()).isNotNull();
}

17 View Source File : Spr7167Tests.java
License : Apache License 2.0
Project Creator : SourceHot

@Test
public void test() {
    ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MyConfig.clreplaced);
    replacedertThat(ctx.getBeanFactory().getBeanDefinition("someDependency").getDescription()).as("someDependency was not post processed").isEqualTo("post processed by MyPostProcessor");
    MyConfig config = ctx.getBean(MyConfig.clreplaced);
    replacedertThat(ClreplacedUtils.isCglibProxy(config)).as("Config clreplaced was not enhanced").isTrue();
}

17 View Source File : VertxWebTestClientContextCustomizer.java
License : Apache License 2.0
Project Creator : snowdrop

@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
    ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    if (beanFactory instanceof BeanDefinitionRegistry) {
        registerWebTestClient((BeanDefinitionRegistry) beanFactory);
    }
}

17 View Source File : ControllerMethodResolver.java
License : MIT License
Project Creator : mindcarver

private static List<HandlerMethodArgumentResolver> initResolvers(ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry reactiveRegistry, ConfigurableApplicationContext context, boolean supportDataBinding, List<HttpMessageReader<?>> readers) {
    ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    boolean requestMappingMethod = !readers.isEmpty() && supportDataBinding;
    // Annotation-based...
    List<HandlerMethodArgumentResolver> result = new ArrayList<>();
    result.add(new RequestParamMethodArgumentResolver(beanFactory, reactiveRegistry, false));
    result.add(new RequestParamMapMethodArgumentResolver(reactiveRegistry));
    result.add(new PathVariableMethodArgumentResolver(beanFactory, reactiveRegistry));
    result.add(new PathVariableMapMethodArgumentResolver(reactiveRegistry));
    result.add(new MatrixVariableMethodArgumentResolver(beanFactory, reactiveRegistry));
    result.add(new MatrixVariableMapMethodArgumentResolver(reactiveRegistry));
    if (!readers.isEmpty()) {
        result.add(new RequestBodyArgumentResolver(readers, reactiveRegistry));
        result.add(new RequestPartMethodArgumentResolver(readers, reactiveRegistry));
    }
    if (supportDataBinding) {
        result.add(new ModelAttributeMethodArgumentResolver(reactiveRegistry, false));
    }
    result.add(new RequestHeaderMethodArgumentResolver(beanFactory, reactiveRegistry));
    result.add(new RequestHeaderMapMethodArgumentResolver(reactiveRegistry));
    result.add(new CookieValueMethodArgumentResolver(beanFactory, reactiveRegistry));
    result.add(new ExpressionValueMethodArgumentResolver(beanFactory, reactiveRegistry));
    result.add(new SessionAttributeMethodArgumentResolver(beanFactory, reactiveRegistry));
    result.add(new RequestAttributeMethodArgumentResolver(beanFactory, reactiveRegistry));
    // Type-based...
    if (!readers.isEmpty()) {
        result.add(new HttpEnreplacedyArgumentResolver(readers, reactiveRegistry));
    }
    result.add(new ModelArgumentResolver(reactiveRegistry));
    if (supportDataBinding) {
        result.add(new ErrorsMethodArgumentResolver(reactiveRegistry));
    }
    result.add(new ServerWebExchangeArgumentResolver(reactiveRegistry));
    result.add(new PrincipalArgumentResolver(reactiveRegistry));
    if (requestMappingMethod) {
        result.add(new SessionStatusMethodArgumentResolver());
    }
    result.add(new WebSessionArgumentResolver(reactiveRegistry));
    // Custom...
    result.addAll(customResolvers.getCustomResolvers());
    // Catch-all...
    result.add(new RequestParamMethodArgumentResolver(beanFactory, reactiveRegistry, true));
    if (supportDataBinding) {
        result.add(new ModelAttributeMethodArgumentResolver(reactiveRegistry, true));
    }
    return result;
}

17 View Source File : BeanCreatingHandlerProviderTests.java
License : Apache License 2.0
Project Creator : langtianya

@Test
public void getHandlerWithBeanFactory() {
    @SuppressWarnings("resource")
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.clreplaced);
    BeanCreatingHandlerProvider<EchoHandler> provider = new BeanCreatingHandlerProvider<EchoHandler>(EchoHandler.clreplaced);
    provider.setBeanFactory(context.getBeanFactory());
    replacedertNotNull(provider.getHandler());
}

17 View Source File : SpringBootstrap.java
License : Apache License 2.0
Project Creator : hank-cp

@Override
protected void afterRefresh(ConfigurableApplicationContext context, ApplicationArguments args) {
    context.getBeanFactory().registerSingleton(BEAN_IMPORTED_BEAN_NAMES, importedBeanNames);
}

/**
 * Called once the {@link ApplicationContext} has been created and prepared, but before sources
 * have been loaded.
 *
 * @param context the application context
 */
@Override
public void contextPrepared(ConfigurableApplicationContext context) {
    log.info("Registering fake REQUEST scope to the context bean factory for command-line tools");
    context.getBeanFactory().registerScope(WebApplicationContext.SCOPE_REQUEST, new SimpleThreadScope());
}

@Test
public void onlyRegisteredOnceWhenThereIsAChildContext() {
    SpringApplicationBuilder parentBuilder = new SpringApplicationBuilder().web(WebApplicationType.NONE).sources(MultipleMBeanExportersConfiguration.clreplaced, SpringApplicationAdminJmxAutoConfiguration.clreplaced);
    SpringApplicationBuilder childBuilder = parentBuilder.child(MultipleMBeanExportersConfiguration.clreplaced, SpringApplicationAdminJmxAutoConfiguration.clreplaced).web(WebApplicationType.NONE);
    try (ConfigurableApplicationContext parent = parentBuilder.run("--" + ENABLE_ADMIN_PROP);
        ConfigurableApplicationContext child = childBuilder.run("--" + ENABLE_ADMIN_PROP)) {
        BeanFactoryUtils.beanOfType(parent.getBeanFactory(), SpringApplicationAdminMXBeanRegistrar.clreplaced);
        replacedertThatExceptionOfType(NoSuchBeanDefinitionException.clreplaced).isThrownBy(() -> BeanFactoryUtils.beanOfType(child.getBeanFactory(), SpringApplicationAdminMXBeanRegistrar.clreplaced));
    }
}

16 View Source File : Application.java
License : Apache License 2.0
Project Creator : syndesisio

public static void main(final String[] args) {
    ConfigurableApplicationContext context = SpringApplication.run(Application.clreplaced, args);
    for (String name : context.getBeanNamesForType(Verifier.clreplaced)) {
        BeanDefinition definition = context.getBeanFactory().getBeanDefinition(name);
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Found Verifier: name={}, factory={}", name, definition.getBeanClreplacedName() != null ? definition.getBeanClreplacedName() : definition.getFactoryBeanName() + "::" + definition.getFactoryMethodName());
        }
    }
    for (String name : context.getBeanNamesForType(MetadataRetrieval.clreplaced)) {
        BeanDefinition definition = context.getBeanFactory().getBeanDefinition(name);
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Found MetaDataAdapter: name={}, factory={}", name, definition.getBeanClreplacedName() != null ? definition.getBeanClreplacedName() : definition.getFactoryBeanName() + "::" + definition.getFactoryMethodName());
        }
    }
}

16 View Source File : SecretManagerPropertySourceIntegrationTests.java
License : Apache License 2.0
Project Creator : spring-cloud

@BeforeClreplaced
public static void prepare() {
    replacedumeThat(System.getProperty("it.secretmanager")).as("Secret manager integration tests are disabled. " + "Please use '-Dit.secretmanager=true' to enable them.").isEqualTo("true");
    // Create the test secret if it does not already currently exist.
    ConfigurableApplicationContext setupContext = new SpringApplicationBuilder(SecretManagerTestConfiguration.clreplaced).web(WebApplicationType.NONE).run();
    SecretManagerTemplate template = setupContext.getBeanFactory().getBean(SecretManagerTemplate.clreplaced);
    if (!template.secretExists(TEST_SECRET_ID)) {
        template.createSecret(TEST_SECRET_ID, "the secret data.");
    }
}

16 View Source File : MockContextCustomizer.java
License : MIT License
Project Creator : pchudzik

/**
 * <p>Will register mock factory and all additional beans required by springmock.</p>
 * <p>
 * <p>It is possible to register and inject more beans preplaceding additionalDefinitions to the constructor</p>
 *
 * @param configurableApplicationContext
 * @param mergedContextConfiguration
 */
public final void customizeContext(ConfigurableApplicationContext configurableApplicationContext, MergedContextConfiguration mergedContextConfiguration) {
    final BeanDefinitionRegistry registry = (BeanDefinitionRegistry) configurableApplicationContext;
    registerDoubleRegistry(registry);
    registerDoubleFactory(configurableApplicationContext.getBeanFactory(), registry);
    registerMockClreplacedResolver(registry);
    registerDoubleDefinitionRegisteringProcessor(registry);
    registerSpyRegistrationPostProcessor(registry);
    registerAdditionalBeanDefinitions(registry, additionalDefinitions);
}

16 View Source File : PluginApplicationContextInitializer.java
License : Apache License 2.0
Project Creator : Nepxion

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    if (!(applicationContext instanceof AnnotationConfigApplicationContext)) {
        /*String bannerShown = System.getProperty(BannerConstant.BANNER_SHOWN, "true");
            if (Boolean.valueOf(bannerShown)) {
                System.out.println("");
                System.out.println("╔═══╗");
                System.out.println("╚╗╔╗║");
                System.out.println(" ║║║╠╦══╦══╦══╦╗╔╦══╦═╦╗ ╔╗");
                System.out.println(" ║║║╠╣══╣╔═╣╔╗║╚╝║║═╣╔╣║ ║║");
                System.out.println("╔╝╚╝║╠══║╚═╣╚╝╠╗╔╣║═╣║║╚═╝║");
                System.out.println("╚═══╩╩══╩══╩══╝╚╝╚══╩╝╚═╗╔╝");
                System.out.println("                      ╔═╝║");
                System.out.println("                      ╚══╝");
                System.out.println("Nepxion Discovery  v" + DiscoveryConstant.DISCOVERY_VERSION);
                System.out.println("");
            }*/
        LogoBanner logoBanner = new LogoBanner(PluginApplicationContextInitializer.clreplaced, "/com/nepxion/discovery/resource/logo.txt", "Welcome to Nepxion", 9, 5, new Color[] { Color.red, Color.green, Color.cyan, Color.blue, Color.yellow, Color.magenta, Color.red, Color.green, Color.cyan }, true);
        NepxionBanner.show(logoBanner, new Description(BannerConstant.VERSION + ":", DiscoveryConstant.DISCOVERY_VERSION, 0, 1), new Description(BannerConstant.GITHUB + ":", BannerConstant.NEPXION_GITHUB + "/Discovery", 0, 1));
        initializeDefaultProperties(applicationContext);
    }
    applicationContext.getBeanFactory().addBeanPostProcessor(new InstantiationAwareBeanPostProcessorAdapter() {

        @Override
        public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
            if (bean instanceof DiscoveryClient) {
                DiscoveryClient discoveryClient = (DiscoveryClient) bean;
                return new DiscoveryClientDecorator(discoveryClient, applicationContext);
            } else {
                return afterInitialization(applicationContext, bean, beanName);
            }
        }
    });
}

See More Examples