org.springframework.context.ConfigurableApplicationContext.getBeansOfType()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(168)

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

ConfigurableApplicationContext.getBeansOfType介绍

暂无

代码示例

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

@Test
public void onlyOneInterceptorIsAvailable() {
  Map<String, JCacheInterceptor> interceptors = ctx.getBeansOfType(JCacheInterceptor.class);
  assertEquals("Only one interceptor should be defined", 1, interceptors.size());
  JCacheInterceptor interceptor = interceptors.values().iterator().next();
  assertEquals("Custom interceptor not defined", TestCacheInterceptor.class, interceptor.getClass());
}

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

@Test
public void onlyOneInterceptorIsAvailable() {
  Map<String, CacheInterceptor> interceptors = this.ctx.getBeansOfType(CacheInterceptor.class);
  assertEquals("Only one interceptor should be defined", 1, interceptors.size());
  CacheInterceptor interceptor = interceptors.values().iterator().next();
  assertEquals("Custom interceptor not defined", TestCacheInterceptor.class, interceptor.getClass());
}

代码示例来源:origin: org.springframework.boot/spring-boot

private int getExitCodeFromMappedException(ConfigurableApplicationContext context,
    Throwable exception) {
  if (context == null || !context.isActive()) {
    return 0;
  }
  ExitCodeGenerators generators = new ExitCodeGenerators();
  Collection<ExitCodeExceptionMapper> beans = context
      .getBeansOfType(ExitCodeExceptionMapper.class).values();
  generators.addAll(exception, beans);
  return generators.getExitCode();
}

代码示例来源:origin: spring-cloud-incubator/spring-cloud-alibaba

SmsConfigProperties.smsProduct, SmsConfigProperties.smsDomain);
Collection<MessageListener> messageListeners = event.getApplicationContext()
    .getBeansOfType(MessageListener.class).values();
if (messageListeners.isEmpty()) {
  return;

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

@Test
public void transactionalEventListenerRegisteredProperly() {
  assertTrue(this.context.containsBean(TransactionManagementConfigUtils
      .TRANSACTIONAL_EVENT_LISTENER_FACTORY_BEAN_NAME));
  assertEquals(1, this.context.getBeansOfType(TransactionalEventListenerFactory.class).size());
}

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

@Test
@SuppressWarnings("resource")
public void testJobElement() throws Exception {
  ConfigurableApplicationContext ctx =
      new ClassPathXmlApplicationContext(
          "org/springframework/batch/core/configuration/xml/AutoRegisteringJobScopeForJobElementTests-context.xml");
  Map<String, JobScope> beans = ctx.getBeansOfType(JobScope.class);
  assertTrue("JobScope not defined properly", beans.size() == 1);
}

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

@Test
@SuppressWarnings("resource")
public void testStepElement() throws Exception {
  ConfigurableApplicationContext ctx =
      new ClassPathXmlApplicationContext(
          "org/springframework/batch/core/configuration/xml/AutoRegisteringJobScopeForStepElementTests-context.xml");
  Map<String, JobScope> beans = ctx.getBeansOfType(JobScope.class);
  assertTrue("JobScope not defined properly", beans.size() == 1);
}

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

@Test
public void credentialsAreClearedByDefault() throws Exception {
  ConfigurableApplicationContext appContext = this.spring.context(CONTEXT)
    .getContext();
  ProviderManager pm = (ProviderManager) appContext
      .getBeansOfType(ProviderManager.class).values().toArray()[0];
  assertThat(pm.isEraseCredentialsAfterAuthentication()).isTrue();
}

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

@Test
@SuppressWarnings("resource")
public void testStepElement() throws Exception {
  ConfigurableApplicationContext ctx = 
    new ClassPathXmlApplicationContext("org/springframework/batch/core/configuration/xml/AutoRegisteringStepScopeForStepElementTests-context.xml");
  Map<String, StepScope> beans = ctx.getBeansOfType(StepScope.class);
  assertTrue("StepScope not defined properly", beans.size() == 1);
}

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

@Test
@SuppressWarnings("resource")
public void testJobElement() throws Exception {
  ConfigurableApplicationContext ctx = 
    new ClassPathXmlApplicationContext("org/springframework/batch/core/configuration/xml/AutoRegisteringStepScopeForJobElementTests-context.xml");
  Map<String, StepScope> beans = ctx.getBeansOfType(StepScope.class);
  assertTrue("StepScope not defined properly", beans.size() == 1);
}

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

@Test
public void clearCredentialsPropertyIsRespected() throws Exception {
  ConfigurableApplicationContext appContext = this.spring.context("<authentication-manager erase-credentials='false'/>")
    .getContext();
  ProviderManager pm = (ProviderManager) appContext
      .getBeansOfType(ProviderManager.class).values().toArray()[0];
  assertThat(pm.isEraseCredentialsAfterAuthentication()).isFalse();
}

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

@Test
public void eventsArePublishedByDefault() throws Exception {
  ConfigurableApplicationContext appContext = this.spring.context(CONTEXT)
    .getContext();
  AuthListener listener = new AuthListener();
  appContext.addApplicationListener(listener);
  ProviderManager pm = (ProviderManager) appContext
      .getBeansOfType(ProviderManager.class).values().toArray()[0];
  Object eventPublisher = FieldUtils.getFieldValue(pm, "eventPublisher");
  assertThat(eventPublisher).isNotNull();
  assertThat(eventPublisher instanceof DefaultAuthenticationEventPublisher).isTrue();
  pm.authenticate(new UsernamePasswordAuthenticationToken("bob", "bobspassword"));
  assertThat(listener.events).hasSize(1);
}

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

@Test
@SuppressWarnings("resource")
public void testStepParserBeanName() throws Exception {
  ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
      "org/springframework/batch/core/configuration/xml/StepParserBeanNameTests-context.xml");
  Map<String, Step> beans = ctx.getBeansOfType(Step.class);
  assertTrue("'s1' bean not found", beans.containsKey("s1"));
  Step s1 = (Step) ctx.getBean("s1");
  assertEquals("wrong name", "s1", s1.getName());
}

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

@Test
@SuppressWarnings("resource")
public void testStepParserCompletionPolicy() throws Exception {
  ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
      "org/springframework/batch/core/configuration/xml/StepParserCompletionPolicyTests-context.xml");
  Map<String, Step> beans = ctx.getBeansOfType(Step.class);
  assertTrue("'s1' bean not found", beans.containsKey("s1"));
  Step s1 = (Step) ctx.getBean("s1");
  CompletionPolicy completionPolicy = getCompletionPolicy(s1);
  assertTrue(completionPolicy instanceof DummyCompletionPolicy);
}

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

@Test
// SEC-1225
public void providersAreRegisteredAsTopLevelBeans() throws Exception {
  ConfigurableApplicationContext context = this.spring.context(CONTEXT)
    .getContext();
  assertThat(context.getBeansOfType(AuthenticationProvider.class)).hasSize(1);
}

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

@Test
@SuppressWarnings("resource")
public void testTaskletStepAttributes() throws Exception {
  ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
      "org/springframework/batch/core/configuration/xml/StepParserTaskletAttributesTests-context.xml");
  @SuppressWarnings({ "rawtypes" })
  Map<String, StepParserStepFactoryBean> beans = ctx.getBeansOfType(StepParserStepFactoryBean.class);
  String factoryName = (String) beans.keySet().toArray()[0];
  @SuppressWarnings("unchecked")
  StepParserStepFactoryBean<Object, Object> factory = beans.get(factoryName);
  TaskletStep bean = (TaskletStep) factory.getObject();
  assertEquals("wrong start-limit:", 25, bean.getStartLimit());
  Object throttleLimit = ReflectionTestUtils.getField(factory, "throttleLimit");
  assertEquals(new Integer(10), throttleLimit);
}

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

@Test
@SuppressWarnings("resource")
public void testStepParserCommitInterval() throws Exception {
  ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
      "org/springframework/batch/core/configuration/xml/StepParserCommitIntervalTests-context.xml");
  Map<String, Step> beans = ctx.getBeansOfType(Step.class);
  assertTrue("'s1' bean not found", beans.containsKey("s1"));
  Step s1 = (Step) ctx.getBean("s1");
  CompletionPolicy completionPolicy = getCompletionPolicy(s1);
  assertTrue(completionPolicy instanceof SimpleCompletionPolicy);
  assertEquals(25, ReflectionTestUtils.getField(completionPolicy, "chunkSize"));
}

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

@Test
public void testInlineHandlersWithStepScope() throws Exception {
  context = new ClassPathXmlApplicationContext(
      "org/springframework/batch/core/configuration/xml/InlineItemHandlerWithStepScopeParserTests-context.xml");
  StepSynchronizationManager.register(new StepExecution("step", new JobExecution(123L)));
  @SuppressWarnings({ "rawtypes" })
  Map<String,ItemReader> readers = context.getBeansOfType(ItemReader.class);
  // Should be 2 each (proxy and target) for the two readers in the steps defined
  assertEquals(4, readers.size());
}

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

@Test
public void testNoHistoryAwareMessageHandler() {
  ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithoutHistoryWriter.xml",
      MessageHistoryIntegrationTests.class);
  Map<String, ConsumerEndpointFactoryBean> cefBeans = ac.getBeansOfType(ConsumerEndpointFactoryBean.class);
  for (ConsumerEndpointFactoryBean cefBean : cefBeans.values()) {
    DirectFieldAccessor bridgeAccessor = new DirectFieldAccessor(cefBean);
    String handlerClassName = bridgeAccessor.getPropertyValue("handler").getClass().getName();
    assertFalse("org.springframework.integration.config.MessageHistoryWritingMessageHandler"
        .equals(handlerClassName));
  }
  ac.close();
}

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

@Test
public void testJpaExecutorBeanIdNaming() throws Exception {
  JpaExecutor jpaExecutor1 = this.context.getBean("jpaInboundChannelAdapter1.jpaExecutor", JpaExecutor.class);
  JpaExecutor jpaExecutor2 = this.context.getBean("jpaInboundChannelAdapter2.jpaExecutor", JpaExecutor.class);
  assertNotNull(jpaExecutor1);
  assertNotNull(jpaExecutor2);
  assertNotSame(jpaExecutor1, jpaExecutor2);
  assertEquals(5, this.context.getBeansOfType(JpaExecutor.class).size());
  JpaExecutor jpaExecutorWithoutId0 =
      this.context.getBean("org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean#0.jpaExecutor",
          JpaExecutor.class);
  JpaExecutor jpaExecutorWithoutId1 =
      this.context.getBean("org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean#1.jpaExecutor",
          JpaExecutor.class);
  assertNotNull(jpaExecutorWithoutId0);
  assertNotNull(jpaExecutorWithoutId1);
  assertNotSame(jpaExecutorWithoutId0, jpaExecutorWithoutId1);
}

相关文章

微信公众号

最新文章

更多

ConfigurableApplicationContext类方法