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

x33g5p2x  于2022-01-15 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(154)

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

ApplicationContext.containsBean介绍

暂无

代码示例

代码示例来源:origin: shuzheng/zheng

/**
 * 是否包含bean
 * @param beanName
 * @return
 */
public static boolean containsBean(String beanName) {
  return context.containsBean(beanName);
}

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

@Override
public void setApplicationContext(@Nullable ApplicationContext applicationContext) {
  this.applicationContext = applicationContext;
  if (applicationContext != null) {
      Assert.state(!applicationContext.containsBean("mvcContentNegotiationManager"),
          "The Java/XML config for Spring MVC and Spring WebFlux cannot both be enabled, " +
          "e.g. via @EnableWebMvc and @EnableWebFlux, in the same application.");
  }
}

代码示例来源:origin: Activiti/Activiti

public Object getValue(ELContext context, Object base, Object property) {
 if (base == null) {
  // according to javadoc, can only be a String
  String key = (String) property;
  if (applicationContext.containsBean(key)) {
   context.setPropertyResolved(true);
   return applicationContext.getBean(key);
  }
 }
 return null;
}

代码示例来源:origin: apache/incubator-dubbo

private InvocationHandler buildInvocationHandler(String referencedBeanName, ReferenceBean referenceBean) {
  ReferenceBeanInvocationHandler handler = localReferenceBeanInvocationHandlerCache.get(referencedBeanName);
  if (handler == null) {
    handler = new ReferenceBeanInvocationHandler(referenceBean);
  }
  if (applicationContext.containsBean(referencedBeanName)) { // Is local @Service Bean or not ?
    // ReferenceBeanInvocationHandler's initialization has to wait for current local @Service Bean has been exported.
    localReferenceBeanInvocationHandlerCache.put(referencedBeanName, handler);
  } else {
    // Remote Reference Bean should initialize immediately
    handler.init();
  }
  return handler;
}

代码示例来源:origin: apache/incubator-dubbo

private InvocationHandler buildInvocationHandler(String referencedBeanName, ReferenceBean referenceBean) {
  ReferenceBeanInvocationHandler handler = localReferenceBeanInvocationHandlerCache.get(referencedBeanName);
  if (handler == null) {
    handler = new ReferenceBeanInvocationHandler(referenceBean);
  }
  if (applicationContext.containsBean(referencedBeanName)) { // Is local @Service Bean or not ?
    // ReferenceBeanInvocationHandler's initialization has to wait for current local @Service Bean has been exported.
    localReferenceBeanInvocationHandlerCache.put(referencedBeanName, handler);
  } else {
    // Remote Reference Bean should initialize immediately
    handler.init();
  }
  return handler;
}

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

/**
 * Return the {@link RequestDataValueProcessor} to use.
 * <p>The default implementation looks in the {@link #getApplicationContext()
 * Spring configuration} for a {@code RequestDataValueProcessor} bean with
 * the name {@link #REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME}.
 * @return the RequestDataValueProcessor, or null if there is none at the
 * application context.
 */
@Nullable
protected RequestDataValueProcessor getRequestDataValueProcessor() {
  ApplicationContext context = getApplicationContext();
  if (context != null && context.containsBean(REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME)) {
    return context.getBean(REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME, RequestDataValueProcessor.class);
  }
  return null;
}

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

@Override
@Nullable
public View resolveViewName(String viewName, Locale locale) throws BeansException {
  ApplicationContext context = obtainApplicationContext();
  if (!context.containsBean(viewName)) {
    // Allow for ViewResolver chaining...
    return null;
  }
  if (!context.isTypeMatch(viewName, View.class)) {
    if (logger.isDebugEnabled()) {
      logger.debug("Found bean named '" + viewName + "' but it does not implement View");
    }
    // Since we're looking into the general ApplicationContext here,
    // let's accept this as a non-match and allow for chaining as well...
    return null;
  }
  return context.getBean(viewName, View.class);
}

代码示例来源:origin: Activiti/Activiti

public void setValue(ELContext context, Object base, Object property, Object value) {
 if (base == null) {
  String key = (String) property;
  if (applicationContext.containsBean(key)) {
   throw new ActivitiException("Cannot set value of '" + property + "', it resolves to a bean defined in the Spring application-context.");
  }
 }
}

代码示例来源:origin: Activiti/Activiti

protected boolean hasConnectorBean(DelegateExecution execution) {
    String implementation = getServiceTaskImplementation(execution);
    return applicationContext.containsBean(implementation)
        && applicationContext.getBean(implementation) instanceof Connector;
  }
}

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

public HandlerMappingIntrospector getObject() {
  if (!this.context.containsBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME)) {
    throw new NoSuchBeanDefinitionException(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME, "A Bean named " + HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME +" of type " + HandlerMappingIntrospector.class.getName()
      + " is required to use MvcRequestMatcher. Please ensure Spring Security & Spring MVC are configured in a shared ApplicationContext.");
  }
  return this.context.getBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME, HandlerMappingIntrospector.class);
}

代码示例来源:origin: apache/incubator-dubbo-spring-boot-project

private Object resolveServiceBean(String serviceBeanName, ServiceBean serviceBean) {
  int index = serviceBeanName.indexOf("#");
  if (index > -1) {
    Class<?> interfaceClass = serviceBean.getInterfaceClass();
    String serviceName = serviceBeanName.substring(index + 1);
    if (applicationContext.containsBean(serviceName)) {
      return applicationContext.getBean(serviceName, interfaceClass);
    }
  }
  return null;
}

代码示例来源:origin: apache/incubator-dubbo

if (context.containsBean(name)) {
  Object bean = context.getBean(name);
  if (type.isInstance(bean)) {

代码示例来源:origin: apache/incubator-dubbo

if (context.containsBean(name)) {
  Object bean = context.getBean(name);
  if (type.isInstance(bean)) {

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

private void assertHasEnvironment(ApplicationContext ctx, Environment expectedEnv) {
  // ensure the custom environment took
  Environment actualEnv = ctx.getEnvironment();
  assertThat(actualEnv, notNullValue());
  assertThat(actualEnv, is(expectedEnv));
  // ensure environment is registered as a bean
  assertThat(ctx.containsBean(ENVIRONMENT_BEAN_NAME), is(true));
}

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

@Test
public void testCustomBeanNameGenerator() {
  ApplicationContext context = new ClassPathXmlApplicationContext(
      "org/springframework/context/annotation/customNameGeneratorTests.xml");
  assertTrue(context.containsBean("testing.fooServiceImpl"));
}

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

@Test
@SuppressWarnings("resource")
public void testClassPathXmlApplicationContext() throws IOException {
  ApplicationContext context = new ClassPathXmlApplicationContext(
      "/org/springframework/web/context/WEB-INF/applicationContext.xml");
  assertTrue("Has father", context.containsBean("father"));
  assertTrue("Has rod", context.containsBean("rod"));
  assertFalse("Hasn't kerry", context.containsBean("kerry"));
  assertTrue("Doesn't have spouse", ((TestBean) context.getBean("rod")).getSpouse() == null);
  assertTrue("myinit not evaluated", "Roderick".equals(((TestBean) context.getBean("rod")).getName()));
  context = new ClassPathXmlApplicationContext(new String[] {
    "/org/springframework/web/context/WEB-INF/applicationContext.xml",
    "/org/springframework/web/context/WEB-INF/context-addition.xml" });
  assertTrue("Has father", context.containsBean("father"));
  assertTrue("Has rod", context.containsBean("rod"));
  assertTrue("Has kerry", context.containsBean("kerry"));
}

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

@Test
public void asyncPostProcessorRegistered() {
  assertTrue(context.containsBean(TaskManagementConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME));
}

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

@Test
public void scheduledPostProcessorRegistered() {
  assertTrue(context.containsBean(TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME));
}

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

@Test
public void classRelativeResourceLoading_ctor() {
  ApplicationContext ctx = new GenericXmlApplicationContext(RELATIVE_CLASS, RESOURCE_NAME);
  assertThat(ctx.containsBean(TEST_BEAN_NAME), is(true));
}

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

@Test
public void fullyQualifiedResourceLoading_ctor() {
  ApplicationContext ctx = new GenericXmlApplicationContext(FQ_RESOURCE_PATH);
  assertThat(ctx.containsBean(TEST_BEAN_NAME), is(true));
}

相关文章