@Override public void registerBeanDefinitions(AnnotationMetadata annotation, BeanDefinitionRegistry registry) { BeanDefinitionBuilder builder = BeanDefinitionBuilder .genericBeanDefinition(GuiceModuleMetadataFactory.class); builder.addPropertyValue("includeFilters", parseFilters(annotation, "includeFilters")); builder.addPropertyValue("excludeFilters", parseFilters(annotation, "excludeFilters")); builder.addPropertyValue("includePatterns", parsePatterns(annotation, "includePatterns")); builder.addPropertyValue("excludePatterns", parsePatterns(annotation, "excludePatterns")); builder.addPropertyValue("includeNames", parseNames(annotation, "includeNames")); builder.addPropertyValue("excludeNames", parseNames(annotation, "excludeNames")); AbstractBeanDefinition definition = builder.getBeanDefinition(); String name = new DefaultBeanNameGenerator().generateBeanName(definition, registry); registry.registerBeanDefinition(name, definition); }
@Test public void customBeanNameGenerator() throws Exception { TestSpringApplication application = new TestSpringApplication( ExampleWebConfig.class); BeanNameGenerator beanNameGenerator = new DefaultBeanNameGenerator(); application.setBeanNameGenerator(beanNameGenerator); this.context = application.run(); verify(application.getLoader()).setBeanNameGenerator(beanNameGenerator); Object actualGenerator = this.context .getBean(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR); assertThat(actualGenerator).isSameAs(beanNameGenerator); }
@Test public void customBeanNameGeneratorWithNonWebApplication() throws Exception { TestSpringApplication application = new TestSpringApplication( ExampleWebConfig.class); application.setWebEnvironment(false); BeanNameGenerator beanNameGenerator = new DefaultBeanNameGenerator(); application.setBeanNameGenerator(beanNameGenerator); this.context = application.run(); verify(application.getLoader()).setBeanNameGenerator(beanNameGenerator); Object actualGenerator = this.context .getBean(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR); assertThat(actualGenerator).isSameAs(beanNameGenerator); }
@Test public void customBeanNameGenerator() throws Exception { TestSpringApplication application = new TestSpringApplication( ExampleWebConfig.class); BeanNameGenerator beanNameGenerator = new DefaultBeanNameGenerator(); application.setBeanNameGenerator(beanNameGenerator); this.context = application.run(); verify(application.getLoader()).setBeanNameGenerator(beanNameGenerator); Object bean = this.context .getBean(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR); assertThat(bean).isSameAs(beanNameGenerator); }
@Test public void customBeanNameGenerator() throws Exception { TestSpringApplication application = new TestSpringApplication( ExampleWebConfig.class); BeanNameGenerator beanNameGenerator = new DefaultBeanNameGenerator(); application.setBeanNameGenerator(beanNameGenerator); this.context = application.run(); verify(application.getLoader()).setBeanNameGenerator(beanNameGenerator); assertThat( this.context .getBean(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR), sameInstance((Object) beanNameGenerator)); }
public BeanDefinition parse(Element element, ParserContext parserContext) { ClassPathBeanDefinitionScanner scanner = new DwrClassPathBeanDefinitionScanner(parserContext.getRegistry()); String basePackage = element.getAttribute("base-package"); // Override - By default Spring uses a name generator that uses AnnotationBeanNameGenerator which uses the name specified on the Component // annotation and if not present uses the simple name. Since our annotation-scanner doesn't scan @Component if two classes with the // same simple name exist in different packages there will be issues. See https://directwebremoting.atlassian.net/browse/DWR-651. scanner.setBeanNameGenerator(new DefaultBeanNameGenerator()); if (!hasText(basePackage)) { if (log.isInfoEnabled()) { log.info("No base package defined for classpath scanning. Traversing the whole JVM classpath"); } } String regex = element.getAttribute("regex"); if (hasText(regex)) { scanner.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(regex))); } String proxies = element.getAttribute("scanRemoteProxy"); if (hasText(proxies) && ("TRUE".equals(proxies.toUpperCase()) || "FALSE".equals(proxies.toUpperCase()))) { scanProxies = Boolean.parseBoolean(proxies); } if (scanProxies) { scanner.addIncludeFilter(new AnnotationTypeFilter(RemoteProxy.class)); } String conv = element.getAttribute("scanDataTransferObject"); if (hasText(conv) && ("TRUE".equals(conv.toUpperCase()) || "FALSE".equals(conv.toUpperCase()))) { scanConverters = Boolean.parseBoolean(conv); } if (scanConverters) { scanner.addIncludeFilter(new AnnotationTypeFilter(DataTransferObject.class)); } String filters = element.getAttribute("scanGlobalFilter"); if (hasText(filters) && ("TRUE".equals(filters.toUpperCase()) || "FALSE".equals(filters.toUpperCase()))) { scanFilters = Boolean.parseBoolean(filters); } if (scanFilters) { scanner.addIncludeFilter(new AnnotationTypeFilter(GlobalFilter.class)); } if (scanProxies | scanConverters | scanFilters) { scanner.scan(basePackage == null ? "" : basePackage); } else { log.warn("Scan is not required if all @RemoteProxy, @DataTransferObject and @GlobalFilter are disabled. Skipping detection"); } return null; }