本文整理了Java中org.springframework.context.ConfigurableApplicationContext.containsBean()
方法的一些代码示例,展示了ConfigurableApplicationContext.containsBean()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ConfigurableApplicationContext.containsBean()
方法的具体详情如下:
包路径:org.springframework.context.ConfigurableApplicationContext
类名称:ConfigurableApplicationContext
方法名:containsBean
暂无
代码示例来源:origin: spring-projects/spring-framework
private void assertEnvironmentBeanRegistered(
ConfigurableApplicationContext ctx) {
// ensure environment is registered as a bean
assertThat(ctx.containsBean(ENVIRONMENT_BEAN_NAME), is(true));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void asyncAspectRegistered() {
assertTrue(context.containsBean(TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void classPathXmlApplicationContext() {
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(XML_PATH);
ctx.setEnvironment(prodEnv);
ctx.refresh();
assertEnvironmentBeanRegistered(ctx);
assertHasEnvironment(ctx, prodEnv);
assertEnvironmentAwareInvoked(ctx, ctx.getEnvironment());
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
代码示例来源: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-framework
@Test
public void fileSystemXmlApplicationContext() throws IOException {
ClassPathResource xml = new ClassPathResource(XML_PATH);
File tmpFile = File.createTempFile("test", "xml");
FileCopyUtils.copy(xml.getFile(), tmpFile);
// strange - FSXAC strips leading '/' unless prefixed with 'file:'
ConfigurableApplicationContext ctx =
new FileSystemXmlApplicationContext(new String[] {"file:" + tmpFile.getPath()}, false);
ctx.setEnvironment(prodEnv);
ctx.refresh();
assertEnvironmentBeanRegistered(ctx);
assertHasEnvironment(ctx, prodEnv);
assertEnvironmentAwareInvoked(ctx, ctx.getEnvironment());
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void loadConfigWhenMultipleWebSecurityConfigurationThenContextLoads() throws Exception {
this.spring.register(ParentConfig.class).autowire();
this.child.register(ChildConfig.class);
this.child.getContext().setParent(this.spring.getContext());
this.child.autowire();
assertThat(this.spring.getContext().getBean("springSecurityFilterChain")).isNotNull();
assertThat(this.child.getContext().getBean("springSecurityFilterChain")).isNotNull();
assertThat(this.spring.getContext().containsBean("springSecurityFilterChain")).isTrue();
assertThat(this.child.getContext().containsBean("springSecurityFilterChain")).isTrue();
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testCustomizeContext() {
// given
ConfigurableApplicationContext context = new GenericApplicationContext();
MergedContextConfiguration mergedConfig = Mockito.mock(MergedContextConfiguration.class);
// when
this.contextCustomizer.customizeContext(context, mergedConfig);
// then
Assert.assertTrue(context.containsBean("jobLauncherTestUtils"));
Assert.assertTrue(context.containsBean("jobRepositoryTestUtils"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void componentScanRespectsProfileAnnotation() {
String xmlLocation = "org/springframework/context/annotation/componentScanRespectsProfileAnnotationTests.xml";
{ // should exclude the profile-annotated bean if active profiles remains unset
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.load(xmlLocation);
context.refresh();
assertThat(context.containsBean(ProfileAnnotatedComponent.BEAN_NAME), is(false));
context.close();
}
{ // should include the profile-annotated bean with active profiles set
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.getEnvironment().setActiveProfiles(ProfileAnnotatedComponent.PROFILE_NAME);
context.load(xmlLocation);
context.refresh();
assertThat(context.containsBean(ProfileAnnotatedComponent.BEAN_NAME), is(true));
context.close();
}
{ // ensure the same works for AbstractRefreshableApplicationContext impls too
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(new String[] { xmlLocation },
false);
context.getEnvironment().setActiveProfiles(ProfileAnnotatedComponent.PROFILE_NAME);
context.refresh();
assertThat(context.containsBean(ProfileAnnotatedComponent.BEAN_NAME), is(true));
context.close();
}
}
代码示例来源:origin: mulesoft/mule
private void doRegisterObject(String key, Object value) throws RegistrationException {
if (springContextInitialised.get()) {
if (applicationContext.containsBean(key)) {
if (logger.isWarnEnabled()) {
logger.warn(
format("Spring registry already contains an object named '%s'. The previous object will be overwritten.",
key));
}
SpringRegistry.this.unregisterObject(key);
}
try {
value = initialiseObject(applicationContext, key, value);
applyLifecycle(value);
applicationContext.getBeanFactory().registerSingleton(key, value);
} catch (Exception e) {
throw new RegistrationException(createStaticMessage("Could not register object for key " + key), e);
}
} else {
// since the context has not yet bean initialized, we register a bean definition instead.
registeredBeanDefinitionsBeforeInitialization.put(key, genericBeanDefinition(ConstantFactoryBean.class)
.addConstructorArgValue(value).getBeanDefinition());
}
}
}
代码示例来源:origin: spring-projects/spring-kafka
if (StringUtils.hasText(endpoint.getGroup()) && this.applicationContext != null) {
List<MessageListenerContainer> containerGroup;
if (this.applicationContext.containsBean(endpoint.getGroup())) {
containerGroup = this.applicationContext.getBean(endpoint.getGroup(), List.class);
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testMapPayloadOutboundChannelAdapter() {
setUp("handlingMapPayloadJdbcOutboundChannelAdapterTest.xml", getClass());
assertTrue(context.containsBean("jdbcAdapter"));
Message<?> message = MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build();
channel.send(message);
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from FOOS");
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
assertEquals("Wrong name", "bar", map.get("name"));
}
代码示例来源:origin: pentaho/pentaho-platform
/**
* @see IPentahoObjectFactory#objectDefined(String)
*/
public boolean objectDefined( String key ) {
return beanFactory.containsBean( key );
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testMapPayloadMapReply() {
setUp("handlingMapPayloadJdbcOutboundGatewayTest.xml", getClass());
assertTrue(this.context.containsBean("jdbcGateway"));
Message<?> message = MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build();
this.channel.send(message);
Message<?> reply = this.messagingTemplate.receive();
assertNotNull(reply);
@SuppressWarnings("unchecked")
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
assertEquals("bar", payload.get("name"));
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from FOOS");
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
assertEquals("Wrong name", "bar", map.get("name"));
JdbcOutboundGateway gateway = context.getBean("jdbcGateway.handler", JdbcOutboundGateway.class);
assertEquals(23, TestUtils.getPropertyValue(gateway, "order"));
Assert.assertTrue(TestUtils.getPropertyValue(gateway, "requiresReply", Boolean.class));
assertEquals(1, adviceCalled);
}
代码示例来源:origin: pentaho/pentaho-platform
/**
* @param clazz Interface or class literal to search for
* @return true if a definition exists
*/
@Override
public boolean objectDefined( Class<?> clazz ) {
return beanFactory.containsBean( clazz.getSimpleName() );
}
代码示例来源:origin: pl.edu.icm.yadda/yadda-remoting-client
public ISessionService getSessionService() {
try {
if (remoteRepCtx.containsBean("AasSessionService")) {
return (ISessionService) remoteRepCtx.getBean("AasSessionService");
}
} catch (Exception e) {
}
return sessionService;
}
代码示例来源:origin: NationalSecurityAgency/datawave
@Override
public boolean containsBean(String name) {
lock.readLock().lock();
try {
return configurableApplicationContext.containsBean(name);
} finally {
lock.readLock().unlock();
}
}
代码示例来源:origin: mercyblitz/thinking-in-spring-boot-samples
public static void main(String[] args) {
ConfigurableApplicationContext context =
new SpringApplicationBuilder(
AnnotationConditionalOnPropertyBootstrap.class)
.web(WebApplicationType.NONE) // 非 Web 应用
.run(args);
System.out.printf("Spring 应用上下文是否包含 enabledValue Bean : %b \n", context.containsBean("enabledValue"));
//关闭 Spring 应用上下文
context.close();
}
代码示例来源:origin: spring-cloud/spring-cloud-stream
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
this.applicationContext = (ConfigurableApplicationContext) applicationContext;
GenericConversionService cs = (GenericConversionService) IntegrationUtils.getConversionService(this.applicationContext.getBeanFactory());
if (this.applicationContext.containsBean("spelConverter")) {
Converter<?,?> converter = (Converter<?, ?>) this.applicationContext.getBean("spelConverter");
cs.addConverter(converter);
}
}
代码示例来源:origin: org.apache.myfaces.orchestra/myfaces-orchestra-core
public Object getBean(String name)
{
if (!getApplicationContext().containsBean(name))
{
return null;
}
return getApplicationContext().getBean(name);
}
代码示例来源:origin: spring-cloud/spring-cloud-dataflow
@Test
public void testNoDataflowConfig() {
SpringApplication app = new SpringApplication(LocalTestNoDataFlowServer.class);
context = app.run(new String[] { "--spring.cloud.kubernetes.enabled=false", "--server.port=0", "--spring.jpa.database=H2", "--spring.flyway.enabled=false" });
assertThat(context.containsBean("appRegistry"), is(false));
}
}
内容来源于网络,如有侵权,请联系作者删除!