Java Code Examples for org.springframework.context.support.ClassPathXmlApplicationContext#getBeansOfType()

The following examples show how to use org.springframework.context.support.ClassPathXmlApplicationContext#getBeansOfType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DubboNamespaceHandlerTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiProtocol() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol.xml");
    ctx.start();

    Map<String, ProtocolConfig> protocolConfigMap = ctx.getBeansOfType(ProtocolConfig.class);
    assertThat(protocolConfigMap.size(), is(2));

    ProtocolConfig rmiProtocolConfig = protocolConfigMap.get("rmi");
    assertThat(rmiProtocolConfig.getPort(), is(10991));

    ProtocolConfig dubboProtocolConfig = protocolConfigMap.get("dubbo");
    assertThat(dubboProtocolConfig.getPort(), is(20881));
}
 
Example 2
Source File: DubboNamespaceHandlerTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimeoutConfig() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/provider-nested-service.xml");
    ctx.start();

    Map<String, ProviderConfig> providerConfigMap = ctx.getBeansOfType(ProviderConfig.class);

    assertThat(providerConfigMap.get("com.alibaba.dubbo.config.ProviderConfig").getTimeout(), is(2000));
}
 
Example 3
Source File: CustomConsumerFactoryPostProcessor.java    From fountain with Apache License 2.0 5 votes vote down vote up
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
    PluggableConsumeActorEnabled meta =
            AnnotationUtils.findAnnotation(bean.getClass(), PluggableConsumeActorEnabled.class);

    if (meta != null) {
        if (!(bean instanceof ConsumeActorAware)) {
            LOGGER.error(
                    "PluggableConsumeActorEnabled annotaion can only be used on ConsumeActorAware "
                            + "implementation");
        }

        LOGGER.info("Start to init IoC container by loading XML bean definitions from {}",
                CLASSPATH_PREFIX + resourceXmlPath);
        iocContainer = new ClassPathXmlApplicationContext(CLASSPATH_PREFIX + resourceXmlPath);
        iocContainer.setParent(applicationContext);
        Map<String, ConsumeActor> consumeActorBeanMap = iocContainer.getBeansOfType(ConsumeActor.class);

        if (CollectionUtils.isEmpty(consumeActorBeanMap)) {
            throw new BeanInitializationException(
                    "No ConsumeActor bean found in " + CLASSPATH_PREFIX + resourceXmlPath);
        }

        if (consumeActorBeanMap.size() > 1) {
            LOGGER.warn("Multiple ConsumeActor beans found in {}{}, and the first one found will be used"
                    + " only", CLASSPATH_PREFIX, resourceXmlPath);
        } else {
            LOGGER.info("Find one ConsumeActor which will be plugged into Consumer as an actor");
        }

        ConsumeActor consumeActor = consumeActorBeanMap.values().toArray(new ConsumeActor[] {})[0];
        ((ConsumeActorAware) bean).setConsumeActor(consumeActor);
    }
    return bean;
}
 
Example 4
Source File: SslContextNBrokerServiceTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
   // System.setProperty("javax.net.debug", "ssl");
   Thread.currentThread().setContextClassLoader(SslContextNBrokerServiceTest.class.getClassLoader());
   context = new ClassPathXmlApplicationContext("org/apache/activemq/transport/tcp/n-brokers-ssl.xml");
   beansOfType = context.getBeansOfType(BrokerService.class);
}
 
Example 5
Source File: SslContextBrokerServiceTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
   Thread.currentThread().setContextClassLoader(SslContextBrokerServiceTest.class.getClassLoader());
   context = new ClassPathXmlApplicationContext("org/apache/activemq/transport/tcp/activemq-ssl.xml");
   Map<String, BrokerService> beansOfType = context.getBeansOfType(BrokerService.class);
   broker = beansOfType.values().iterator().next();
   connector = broker.getTransportConnectors().get(0);
}