Java Code Examples for com.alibaba.spring.util.BeanUtils

The following examples show how to use com.alibaba.spring.util.BeanUtils. These examples are extracted from open source projects. 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
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
@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
@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
@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
/**
 * {@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
@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 Project: nacos-spring-project   Source File: NacosBeanUtils.java    License: 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
@Test
public void testNoopOrderedHiddenHttpMethodFilter() throws ServletException, IOException {

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

}
 
Example 9
@Test
public void testNoopOrderedHttpPutFormContentFilter() throws ServletException, IOException {

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

}