本文整理了Java中org.springframework.context.ConfigurableApplicationContext.getBeanNamesForType()
方法的一些代码示例,展示了ConfigurableApplicationContext.getBeanNamesForType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ConfigurableApplicationContext.getBeanNamesForType()
方法的具体详情如下:
包路径:org.springframework.context.ConfigurableApplicationContext
类名称:ConfigurableApplicationContext
方法名:getBeanNamesForType
暂无
代码示例来源:origin: spring-projects/spring-batch
protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) {
if (parentBeanFactory != null) {
GenericApplicationContextFactory.this.prepareBeanFactory(parentBeanFactory, beanFactory);
for (Class<? extends BeanFactoryPostProcessor> cls : getBeanFactoryPostProcessorClasses()) {
for (String name : parent.getBeanNamesForType(cls)) {
beanFactory.registerSingleton(name, (parent.getBean(name)));
}
}
}
}
代码示例来源:origin: spring-projects/spring-batch
String[] names = context.getBeanNamesForType(Job.class);
代码示例来源:origin: spring-cloud/spring-cloud-gateway
@Test
public void noHiddenHttpMethodFilter() {
try (ConfigurableApplicationContext ctx =
SpringApplication.run(NoHiddenHttpMethodFilterConfig.class, "--spring.jmx.enabled=false")) {
assertThat(ctx.getEnvironment().getProperty("spring.webflux.hiddenmethod.filter.enabled"))
.isEqualTo("false");
assertThat(ctx.getBeanNamesForType(HiddenHttpMethodFilter.class)).isEmpty();
}
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testGetJobName() {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(), "trivial-context.xml")));
assertEquals("test-job", factory.createApplicationContext().getBeanNamesForType(Job.class)[0]);
}
代码示例来源:origin: spring-projects/spring-batch
@SuppressWarnings("resource")
@Test
public void testParentConfigurationInherited() {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(), "child-context.xml")));
factory.setApplicationContext(new ClassPathXmlApplicationContext(ClassUtils.addResourcePathToPackagePath(
getClass(), "parent-context.xml")));
ConfigurableApplicationContext context = factory.createApplicationContext();
assertEquals("test-job", context.getBeanNamesForType(Job.class)[0]);
assertEquals("bar", context.getBean("test-job", Job.class).getName());
assertEquals(4, context.getBean("foo", Foo.class).values[1], 0.01);
}
代码示例来源:origin: spring-projects/spring-batch
@SuppressWarnings("resource")
@Test
public void testBeanFactoryPostProcessorOrderRespected() {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(), "placeholder-context.xml")));
factory.setApplicationContext(new ClassPathXmlApplicationContext(ClassUtils.addResourcePathToPackagePath(
getClass(), "parent-context.xml")));
ConfigurableApplicationContext context = factory.createApplicationContext();
assertEquals("test-job", context.getBeanNamesForType(Job.class)[0]);
assertEquals("spam", context.getBean("test-job", Job.class).getName());
}
代码示例来源:origin: spring-projects/spring-batch
@SuppressWarnings("resource")
@Test
public void testBeanFactoryPostProcessorsNotCopied() {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(), "child-context.xml")));
factory.setApplicationContext(new ClassPathXmlApplicationContext(ClassUtils.addResourcePathToPackagePath(
getClass(), "parent-context.xml")));
@SuppressWarnings("unchecked")
Class<? extends BeanFactoryPostProcessor>[] classes = (Class<? extends BeanFactoryPostProcessor>[]) new Class<?>[0];
factory.setBeanFactoryPostProcessorClasses(classes);
ConfigurableApplicationContext context = factory.createApplicationContext();
assertEquals("test-job", context.getBeanNamesForType(Job.class)[0]);
assertEquals("${foo}", context.getBean("test-job", Job.class).getName());
assertEquals(4, context.getBean("foo", Foo.class).values[1], 0.01);
}
代码示例来源:origin: spring-projects/spring-batch
@SuppressWarnings("resource")
@Test
public void testBeanFactoryConfigurationNotCopied() {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(),
"child-context.xml")));
factory.setApplicationContext(new ClassPathXmlApplicationContext(ClassUtils.addResourcePathToPackagePath(
getClass(), "parent-context.xml")));
factory.setCopyConfiguration(false);
ConfigurableApplicationContext context = factory.createApplicationContext();
assertEquals("test-job", context.getBeanNamesForType(Job.class)[0]);
assertEquals("bar", context.getBean("test-job", Job.class).getName());
// The CustomEditorConfigurer is a BeanFactoryPostProcessor so the
// editor gets copied anyway!
assertEquals(4, context.getBean("foo", Foo.class).values[1], 0.01);
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testBeanFactoryProfileRespected() {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(
new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(), "profiles.xml")));
@SuppressWarnings("resource")
ClassPathXmlApplicationContext parentContext = new ClassPathXmlApplicationContext(ClassUtils.addResourcePathToPackagePath(
getClass(), "parent-context.xml"));
parentContext.getEnvironment().setActiveProfiles("preferred");
factory.setApplicationContext(parentContext);
@SuppressWarnings("resource")
ConfigurableApplicationContext context = factory.createApplicationContext();
assertEquals("test-job", context.getBeanNamesForType(Job.class)[0]);
assertEquals("spam", context.getBean("test-job", Job.class).getName());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testParentConfigurationInheritedMultipleConfigs() {
Resource resource1 = new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(),
"abstract-context.xml"));
Resource resource2 = new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(),
"child-context-with-abstract-job.xml"));
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(resource1, resource2);
ConfigurableApplicationContext context = factory.createApplicationContext();
assertEquals("concrete-job", context.getBeanNamesForType(Job.class)[0]);
assertEquals("bar", context.getBean("concrete-job", Job.class).getName());
assertEquals(4, context.getBean("foo", Foo.class).values[1], 0.01);
assertNotNull(context.getBean("concrete-job", JobSupport.class).getStep("step31"));
assertNotNull(context.getBean("concrete-job", JobSupport.class).getStep("step32"));
boolean autowiredFound = false;
for (BeanPostProcessor postProcessor : ((AbstractBeanFactory) context.getBeanFactory()).getBeanPostProcessors()) {
if (postProcessor instanceof AutowiredAnnotationBeanPostProcessor) {
autowiredFound = true;
}
}
assertTrue(autowiredFound);
}
代码示例来源:origin: NationalSecurityAgency/datawave
@Override
public String[] getBeanNamesForType(Class<?> type) {
lock.readLock().lock();
try {
return configurableApplicationContext.getBeanNamesForType(type);
} finally {
lock.readLock().unlock();
}
}
代码示例来源:origin: spring-cloud/spring-cloud-task
private void verifyEnvironment() {
int configurers = this.context.getBeanNamesForType(TaskConfigurer.class).length;
// retrieve the count of dataSources (without instantiating them) excluding DataSource proxy beans
long dataSources = Arrays.stream(this.context.getBeanNamesForType(DataSource.class))
.filter((name -> !ScopedProxyUtils.isScopedTarget(name))).count();
if(configurers == 0 && dataSources > 1) {
throw new IllegalStateException("To use the default TaskConfigurer the context must contain no more than" +
" one DataSource, found " + dataSources);
}
}
}
代码示例来源:origin: org.springframework.cloud/spring-cloud-task-core
private void verifyEnvironment() {
int configurers = this.context.getBeanNamesForType(TaskConfigurer.class).length;
// retrieve the count of dataSources (without instantiating them) excluding DataSource proxy beans
long dataSources = Arrays.stream(this.context.getBeanNamesForType(DataSource.class))
.filter((name -> !ScopedProxyUtils.isScopedTarget(name))).count();
if(configurers == 0 && dataSources > 1) {
throw new IllegalStateException("To use the default TaskConfigurer the context must contain no more than" +
" one DataSource, found " + dataSources);
}
}
}
代码示例来源:origin: keets2012/Lottor
/**
* 获取bean的名字
*
* @param type 类型
* @return bean名字
*/
public String getBeanName(Class type) {
Assert.notNull(type);
return cfgContext.getBeanNamesForType(type)[0];
}
代码示例来源:origin: org.springframework.batch/spring-batch-core
protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) {
if (parentBeanFactory != null) {
GenericApplicationContextFactory.this.prepareBeanFactory(parentBeanFactory, beanFactory);
for (Class<? extends BeanFactoryPostProcessor> cls : getBeanFactoryPostProcessorClasses()) {
for (String name : parent.getBeanNamesForType(cls)) {
beanFactory.registerSingleton(name, (parent.getBean(name)));
}
}
}
}
代码示例来源:origin: org.springframework.batch.core/org.motechproject.org.springframework.batch.core
protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) {
if (parentBeanFactory != null) {
GenericApplicationContextFactory.this.prepareBeanFactory(parentBeanFactory, beanFactory);
for (Class<? extends BeanFactoryPostProcessor> cls : getBeanFactoryPostProcessorClasses()) {
for (String name : parent.getBeanNamesForType(cls)) {
beanFactory.registerSingleton(name, (parent.getBean(name)));
}
}
}
}
代码示例来源:origin: apache/servicemix-bundles
protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) {
if (parentBeanFactory != null) {
GenericApplicationContextFactory.this.prepareBeanFactory(parentBeanFactory, beanFactory);
for (Class<? extends BeanFactoryPostProcessor> cls : getBeanFactoryPostProcessorClasses()) {
for (String name : parent.getBeanNamesForType(cls)) {
beanFactory.registerSingleton(name, (parent.getBean(name)));
}
}
}
}
代码示例来源:origin: org.springframework.cloud/spring-cloud-netflix-eureka-client
@PostConstruct
public void init() {
if (this.context.getParent() != null) {
if (this.context.getBeanNamesForType(EurekaClient.class).length > 0
&& this.context.getParent()
.getBeanNamesForType(EurekaClient.class).length > 0) {
// If the parent has a EurekaClient as well it should be shutdown, so the
// local one can register accurate instance info
this.context.getParent().getBean(EurekaClient.class).shutdown();
}
}
}
代码示例来源:origin: spring-cloud/spring-cloud-commons
@Test
public void doesNotCreateCloudHypermediaPropertiesifNotActive() {
try (ConfigurableApplicationContext context = getApplicationContext(
Config.class)) {
assertThat(context.getBeanNamesForType(CloudHypermediaProperties.class),
is(arrayWithSize(0)));
}
}
代码示例来源:origin: spring-cloud/spring-cloud-commons
@Test
public void doesNotRegisterResourceRefresherIfNoDiscoveredResourceIsDefined() {
try (ConfigurableApplicationContext context = getApplicationContext(
Config.class)) {
assertThat(context.getBeansOfType(RemoteResource.class).values(), hasSize(0));
assertThat(context.getBeanNamesForType(RemoteResourceRefresher.class),
is(arrayWithSize(0)));
}
}
内容来源于网络,如有侵权,请联系作者删除!