com.alibaba.spring.util.BeanUtils Java Examples

The following examples show how to use com.alibaba.spring.util.BeanUtils. 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: AnnotationNacosInjectedBeanPostProcessor.java    From nacos-spring-project with Apache License 2.0 5 votes vote down vote up
private void initNacosServiceBeanBuilderMap(
		ConfigurableListableBeanFactory beanFactory) {

	Class<AbstractNacosServiceBeanBuilder> builderClass = AbstractNacosServiceBeanBuilder.class;

	String[] beanNames = BeanUtils.getBeanNames(beanFactory, builderClass);
	if (beanNames.length == 0) {
		throw new NoSuchBeanDefinitionException(builderClass,
				format("Please check the BeanDefinition of %s in Spring BeanFactory",
						builderClass));
	}

	Collection<AbstractNacosServiceBeanBuilder> serviceBeanBuilders = new ArrayList<AbstractNacosServiceBeanBuilder>(
			beanNames.length);
	for (String beanName : beanNames) {
		serviceBeanBuilders.add(beanFactory.getBean(beanName, builderClass));
	}

	if (serviceBeanBuilders.isEmpty()) {
		throw new NoSuchBeanDefinitionException(builderClass,
				format("Please check the BeanDefinition of %s in Spring BeanFactory",
						builderClass));
	}

	Map<Class<?>, AbstractNacosServiceBeanBuilder> builderMap = new HashMap<Class<?>, AbstractNacosServiceBeanBuilder>(
			serviceBeanBuilders.size());

	for (AbstractNacosServiceBeanBuilder serviceBeanBuilder : serviceBeanBuilders) {
		Class<?> type = serviceBeanBuilder.getType();
		builderMap.put(type, serviceBeanBuilder);
	}

	// Should not be modified in future
	this.nacosServiceBeanBuilderMap = unmodifiableMap(builderMap);
}
 
Example #2
Source File: EnableConfigurationBeanBindingTestForMultipleBinding.java    From spring-context-support with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    aUser = context.getBean("a", User.class);
    bUser = context.getBean("b", User.class);
    users = BeanUtils.getSortedBeans(context, User.class);
    configurationBeanBindingPostProcessor = context.getBean("configurationBeanBindingPostProcessor", ConfigurationBeanBindingPostProcessor.class);
}
 
Example #3
Source File: ExclusiveViewResolverConfigurationDisabledTest.java    From spring-boot-web-support with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testExclusiveViewResolverConfigurationDisabled() {

    Assert.assertFalse(BeanUtils.isBeanPresent(applicationContext, ExclusiveViewResolverConfiguration.class));
    Assert.assertFalse(BeanUtils.isBeanPresent(applicationContext, ExclusiveViewResolverApplicationListener.class));

    ContentNegotiatingViewResolver contentNegotiatingViewResolver =
            applicationContext.getBean(ContentNegotiatingViewResolver.class);

    Assert.assertNotNull(contentNegotiatingViewResolver);

    List<ViewResolver> viewResolvers = contentNegotiatingViewResolver.getViewResolvers();

    Assert.assertTrue(viewResolvers.size() > 1);

    ThymeleafViewResolver thymeleafViewResolver =
            applicationContext.getBean("thymeleafViewResolver", ThymeleafViewResolver.class);

    Assert.assertTrue(viewResolvers.contains(thymeleafViewResolver));

}
 
Example #4
Source File: ExclusiveViewResolverConfigurationTest.java    From spring-boot-web-support with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testExclusiveViewResolverConfiguration() {

    Assert.assertTrue(BeanUtils.isBeanPresent(applicationContext, ExclusiveViewResolverConfiguration.class));
    Assert.assertTrue(BeanUtils.isBeanPresent(applicationContext, ExclusiveViewResolverApplicationListener.class));

    ContentNegotiatingViewResolver contentNegotiatingViewResolver =
            applicationContext.getBean(ContentNegotiatingViewResolver.class);

    Assert.assertNotNull(contentNegotiatingViewResolver);

    List<ViewResolver> viewResolvers = contentNegotiatingViewResolver.getViewResolvers();

    Assert.assertEquals(1, viewResolvers.size());

    ThymeleafViewResolver thymeleafViewResolver =
            applicationContext.getBean("thymeleafViewResolver", ThymeleafViewResolver.class);

    Assert.assertEquals(thymeleafViewResolver, viewResolvers.get(0));

}
 
Example #5
Source File: WebMvcUtils.java    From spring-webmvc-support with GNU General Public License v3.0 3 votes vote down vote up
/**
 * {@link RequestMappingHandlerMapping} from {@link WebApplicationContext}
 *
 * @param webApplicationContext {@link WebApplicationContext}
 * @return {@link RequestMappingHandlerMapping}
 */
public static RequestMappingHandlerMapping getRequestMappingHandlerMapping(WebApplicationContext webApplicationContext) {

    RequestMappingHandlerMapping requestMappingHandlerMapping =
            BeanUtils.getOptionalBean(webApplicationContext, RequestMappingHandlerMapping.class);

    return requestMappingHandlerMapping;

}
 
Example #6
Source File: ContentNegotiationManagerConfigurationDisabledTest.java    From spring-boot-web-support with GNU General Public License v3.0 3 votes vote down vote up
@Test
public void testContentNegotiationManagerConfigurationOnDisabled() {

    Assert.assertFalse(BeanUtils.isBeanPresent(applicationContext, ContentNegotiationManagerConfiguration.class));

    ContentNegotiationManager contentNegotiationManager =
            contentNegotiatingViewResolver.getContentNegotiationManager();

    List<ContentNegotiationStrategy> strategies = contentNegotiationManager.getStrategies();

    Assert.assertEquals(1, strategies.size());
    Assert.assertTrue(contains(HeaderContentNegotiationStrategy.class, strategies));

}
 
Example #7
Source File: NacosBeanUtils.java    From nacos-spring-project with Apache License 2.0 3 votes vote down vote up
/**
 * Is {@link BeanDefinition} present in {@link BeanDefinitionRegistry}
 *
 * @param registry {@link BeanDefinitionRegistry}
 * @param beanName the name of bean
 * @param targetBeanClass the type of bean
 * @return If Present , return <code>true</code>
 */
public static boolean isBeanDefinitionPresent(BeanDefinitionRegistry registry,
		String beanName, Class<?> targetBeanClass) {
	String[] beanNames = BeanUtils.getBeanNames((ListableBeanFactory) registry,
			targetBeanClass);
	return ArrayUtils.contains(beanNames, beanName);
}
 
Example #8
Source File: SpeedupWebMvcAutoConfigurationDisabledTest.java    From spring-boot-web-support with GNU General Public License v3.0 2 votes vote down vote up
@Test
public void testNoopOrderedHiddenHttpMethodFilter() throws ServletException, IOException {

    Assert.assertFalse(BeanUtils.isBeanPresent(applicationContext, NoopOrderedHiddenHttpMethodFilter.class));

}
 
Example #9
Source File: SpeedupWebMvcAutoConfigurationDisabledTest.java    From spring-boot-web-support with GNU General Public License v3.0 2 votes vote down vote up
@Test
public void testNoopOrderedHttpPutFormContentFilter() throws ServletException, IOException {

    Assert.assertFalse(BeanUtils.isBeanPresent(applicationContext, NoopOrderedHttpPutFormContentFilter.class));

}