Search in sources :

Example 66 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project turbo-rpc by hank-whu.

the class TurboClientStarter method extractTurboServiceClassList.

private Collection<Class<?>> extractTurboServiceClassList(ConfigurableListableBeanFactory beanFactory) {
    LocalDateTime startTime = LocalDateTime.now();
    Set<Class<?>> turboServiceSet = new HashSet<>();
    String[] beanNames = beanFactory.getBeanDefinitionNames();
    for (int i = 0; i < beanNames.length; i++) {
        String beanName = beanNames[i];
        BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
        String beanClassName = beanDefinition.getBeanClassName();
        extractTurboServiceClass(turboServiceSet, beanClassName);
    }
    if (logger.isInfoEnabled()) {
        LocalDateTime finishTime = LocalDateTime.now();
        Duration duration = Duration.between(startTime, finishTime);
        String turboServiceString = // 
        turboServiceSet.stream().map(// 
        clazz -> clazz.getName()).collect(Collectors.joining(",", "[", "]"));
        logger.info("扫描到TurboService: " + turboServiceString);
        logger.info("扫描TurboService耗时: " + duration);
    }
    return turboServiceSet;
}
Also used : LocalDateTime(java.time.LocalDateTime) Ordered(org.springframework.core.Ordered) TurboService(rpc.turbo.annotation.TurboService) Collection(java.util.Collection) BeanFactoryPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor) LocalDateTime(java.time.LocalDateTime) Set(java.util.Set) BeansException(org.springframework.beans.BeansException) UPPER_CAMEL(com.google.common.base.CaseFormat.UPPER_CAMEL) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) LOWER_CAMEL(com.google.common.base.CaseFormat.LOWER_CAMEL) HashSet(java.util.HashSet) BeanPostProcessor(org.springframework.beans.factory.config.BeanPostProcessor) PreDestroy(javax.annotation.PreDestroy) TurboFailover(rpc.turbo.annotation.TurboFailover) TurboClient(rpc.turbo.client.TurboClient) ReflectUtils(rpc.turbo.util.ReflectUtils) Duration(java.time.Duration) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ClientConfig(rpc.turbo.config.client.ClientConfig) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Duration(java.time.Duration) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) HashSet(java.util.HashSet)

Example 67 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-cloud-stream by spring-cloud.

the class DestinationPublishingMetricsAutoConfiguration method metersPublisherBindingRegistrant.

@Bean
public BeanFactoryPostProcessor metersPublisherBindingRegistrant() {
    return new BeanFactoryPostProcessor() {

        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            RootBeanDefinition emitterBindingDefinition = new RootBeanDefinition(BindableProxyFactory.class);
            emitterBindingDefinition.getConstructorArgumentValues().addGenericArgumentValue(MetersPublisherBinding.class);
            ((DefaultListableBeanFactory) beanFactory).registerBeanDefinition(MetersPublisherBinding.class.getName(), emitterBindingDefinition);
        }
    };
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanFactoryPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 68 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project archiva by apache.

the class ArchivaDavResourceFactoryTest method testRequestMetadataRepoIsLegacy.

@Test
public void testRequestMetadataRepoIsLegacy() throws Exception {
    ManagedRepositoryContent legacyRepo = createManagedRepositoryContent(LEGACY_REPO);
    ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
    RepositoryContentProvider provider = createRepositoryContentProvider(legacyRepo);
    beanFactory.registerSingleton("repositoryContentProvider#legacy", provider);
    RepositoryContentFactory repoContentFactory = applicationContext.getBean("repositoryContentFactory#default", RepositoryContentFactory.class);
    repoContentFactory.getRepositoryContentProviders().add(provider);
    defaultManagedRepositoryAdmin.addManagedRepository(createManagedRepository(LEGACY_REPO, Paths.get("target/test-classes/" + LEGACY_REPO).toString(), "legacy"), false, null);
    DavResourceLocator locator = new ArchivaDavResourceLocator("", "/repository/" + LEGACY_REPO + "/eclipse/maven-metadata.xml", LEGACY_REPO, new ArchivaDavLocatorFactory());
    // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
    RepositoryRequest repoRequest = new RepositoryRequest();
    resourceFactory.setRepositoryRequest(repoRequest);
    try {
        archivaConfigurationControl.reset();
        expect(archivaConfiguration.getConfiguration()).andReturn(config).times(2);
        expect(repoFactory.getManagedRepositoryContent(LEGACY_REPO)).andReturn(legacyRepo);
        expect(request.getMethod()).andReturn("GET").times(3);
        expect(request.getRemoteAddr()).andReturn("http://localhost:8080").times(3);
        expect(request.getDavSession()).andReturn(new ArchivaDavSession()).times(2);
        expect(request.getContextPath()).andReturn("").times(2);
        archivaConfigurationControl.replay();
        repoContentFactoryControl.replay();
        requestControl.replay();
        resourceFactory.createResource(locator, request, response);
        archivaConfigurationControl.verify();
        repoContentFactoryControl.verify();
        requestControl.verify();
        fail("A 404 error should have been thrown!");
    } catch (DavException e) {
        assertEquals(404, e.getErrorCode());
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) RepositoryContentProvider(org.apache.archiva.repository.RepositoryContentProvider) DavException(org.apache.jackrabbit.webdav.DavException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) RepositoryRequest(org.apache.archiva.repository.content.maven2.RepositoryRequest) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) RepositoryContentFactory(org.apache.archiva.repository.RepositoryContentFactory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator) Test(org.junit.Test)

Example 69 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-integration by spring-projects.

the class GatewayParserTests method testFactoryBeanObjectTypeWithServiceInterface.

@Test
public void testFactoryBeanObjectTypeWithServiceInterface() throws Exception {
    ConfigurableListableBeanFactory beanFactory = ((GenericApplicationContext) context).getBeanFactory();
    Object attribute = beanFactory.getMergedBeanDefinition("&oneWay").getAttribute(IntegrationConfigUtils.FACTORY_BEAN_OBJECT_TYPE);
    assertEquals(TestService.class.getName(), attribute);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) TestService(org.springframework.integration.gateway.TestService) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Test(org.junit.Test)

Example 70 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-integration by spring-projects.

the class ApplicationEventListeningMessageProducerTests method testPayloadEvents.

@Test
public void testPayloadEvents() {
    GenericApplicationContext ctx = TestUtils.createTestApplicationContext();
    ConfigurableListableBeanFactory beanFactory = ctx.getBeanFactory();
    QueueChannel channel = new QueueChannel();
    ApplicationEventListeningMessageProducer listenerMessageProducer = new ApplicationEventListeningMessageProducer();
    listenerMessageProducer.setOutputChannel(channel);
    listenerMessageProducer.setEventTypes(String.class);
    beanFactory.registerSingleton("testListenerMessageProducer", listenerMessageProducer);
    ctx.refresh();
    ctx.publishEvent("foo");
    Message<?> receive = channel.receive(10000);
    assertNotNull(receive);
    assertEquals("foo", receive.getPayload());
    ctx.close();
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) QueueChannel(org.springframework.integration.channel.QueueChannel) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Test(org.junit.Test)

Aggregations

ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)104 Test (org.junit.Test)16 Test (org.junit.jupiter.api.Test)15 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)13 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)12 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)10 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)10 ApplicationContext (org.springframework.context.ApplicationContext)9 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)8 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)7 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)7 XmlWebApplicationContext (org.springframework.web.context.support.XmlWebApplicationContext)7 Map (java.util.Map)6 BeanFactory (org.springframework.beans.factory.BeanFactory)6 ListableBeanFactory (org.springframework.beans.factory.ListableBeanFactory)6 Collectors (java.util.stream.Collectors)5 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)5 HashMap (java.util.HashMap)4 BeanFactoryPostProcessor (org.springframework.beans.factory.config.BeanFactoryPostProcessor)4 SimpleApplicationEventMulticaster (org.springframework.context.event.SimpleApplicationEventMulticaster)4