Java Code Examples for org.springframework.context.annotation.AnnotatedBeanDefinitionReader#setScopeMetadataResolver()
The following examples show how to use
org.springframework.context.annotation.AnnotatedBeanDefinitionReader#setScopeMetadataResolver() .
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: SpringAtInjectTck.java From spring-analysis-note with MIT License | 6 votes |
public static Test suite() { GenericApplicationContext ac = new GenericApplicationContext(); AnnotatedBeanDefinitionReader bdr = new AnnotatedBeanDefinitionReader(ac); bdr.setScopeMetadataResolver(new Jsr330ScopeMetadataResolver()); bdr.registerBean(Convertible.class); bdr.registerBean(DriversSeat.class, Drivers.class); bdr.registerBean(Seat.class, Primary.class); bdr.registerBean(V8Engine.class); bdr.registerBean(SpareTire.class, "spare"); bdr.registerBean(Cupholder.class); bdr.registerBean(Tire.class, Primary.class); bdr.registerBean(FuelTank.class); ac.refresh(); Car car = ac.getBean(Car.class); return Tck.testsFor(car, false, true); }
Example 2
Source File: SpringAtInjectTck.java From java-technology-stack with MIT License | 6 votes |
public static Test suite() { GenericApplicationContext ac = new GenericApplicationContext(); AnnotatedBeanDefinitionReader bdr = new AnnotatedBeanDefinitionReader(ac); bdr.setScopeMetadataResolver(new Jsr330ScopeMetadataResolver()); bdr.registerBean(Convertible.class); bdr.registerBean(DriversSeat.class, Drivers.class); bdr.registerBean(Seat.class, Primary.class); bdr.registerBean(V8Engine.class); bdr.registerBean(SpareTire.class, "spare"); bdr.registerBean(Cupholder.class); bdr.registerBean(Tire.class, Primary.class); bdr.registerBean(FuelTank.class); ac.refresh(); Car car = ac.getBean(Car.class); return Tck.testsFor(car, false, true); }
Example 3
Source File: SpringAtInjectTck.java From spring4-understanding with Apache License 2.0 | 6 votes |
public static Test suite() { GenericApplicationContext ac = new GenericApplicationContext(); AnnotatedBeanDefinitionReader bdr = new AnnotatedBeanDefinitionReader(ac); bdr.setScopeMetadataResolver(new Jsr330ScopeMetadataResolver()); bdr.registerBean(Convertible.class); bdr.registerBean(DriversSeat.class, Drivers.class); bdr.registerBean(Seat.class, Primary.class); bdr.registerBean(V8Engine.class); bdr.registerBean(SpareTire.class, "spare"); bdr.registerBean(Cupholder.class); bdr.registerBean(Tire.class, Primary.class); bdr.registerBean(FuelTank.class); ac.refresh(); Car car = ac.getBean(Car.class); return Tck.testsFor(car, false, true); }
Example 4
Source File: SpringInitializer.java From Mycat-openEP with Apache License 2.0 | 5 votes |
private static void initAnnotatedConf(GenericApplicationContext context){ Class componentScanAnnotated=ProcessInfo.getAnnotationInitClass(); if(componentScanAnnotated!=null){ AnnotatedGenericBeanDefinition def=new AnnotatedGenericBeanDefinition(ProcessInfo.getAnnotationInitClass()); AnnotatedBeanDefinitionReader reader=new AnnotatedBeanDefinitionReader(context); AnnotationScopeMetadataResolver resolver=new AnnotationScopeMetadataResolver(); resolver.resolveScopeMetadata(def); reader.setScopeMetadataResolver(resolver); } }
Example 5
Source File: AnnotationConfigWebApplicationContext.java From spring-analysis-note with MIT License | 4 votes |
/** * Register a {@link org.springframework.beans.factory.config.BeanDefinition} for * any classes specified by {@link #register(Class...)} and scan any packages * specified by {@link #scan(String...)}. * <p>For any values specified by {@link #setConfigLocation(String)} or * {@link #setConfigLocations(String[])}, attempt first to load each location as a * class, registering a {@code BeanDefinition} if class loading is successful, * and if class loading fails (i.e. a {@code ClassNotFoundException} is raised), * assume the value is a package and attempt to scan it for annotated classes. * <p>Enables the default set of annotation configuration post processors, such that * {@code @Autowired}, {@code @Required}, and associated annotations can be used. * <p>Configuration class bean definitions are registered with generated bean * definition names unless the {@code value} attribute is provided to the stereotype * annotation. * @param beanFactory the bean factory to load bean definitions into * @see #register(Class...) * @see #scan(String...) * @see #setConfigLocation(String) * @see #setConfigLocations(String[]) * @see AnnotatedBeanDefinitionReader * @see ClassPathBeanDefinitionScanner */ @Override protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) { AnnotatedBeanDefinitionReader reader = getAnnotatedBeanDefinitionReader(beanFactory); ClassPathBeanDefinitionScanner scanner = getClassPathBeanDefinitionScanner(beanFactory); BeanNameGenerator beanNameGenerator = getBeanNameGenerator(); if (beanNameGenerator != null) { reader.setBeanNameGenerator(beanNameGenerator); scanner.setBeanNameGenerator(beanNameGenerator); beanFactory.registerSingleton(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR, beanNameGenerator); } ScopeMetadataResolver scopeMetadataResolver = getScopeMetadataResolver(); if (scopeMetadataResolver != null) { reader.setScopeMetadataResolver(scopeMetadataResolver); scanner.setScopeMetadataResolver(scopeMetadataResolver); } if (!this.annotatedClasses.isEmpty()) { if (logger.isDebugEnabled()) { logger.debug("Registering annotated classes: [" + StringUtils.collectionToCommaDelimitedString(this.annotatedClasses) + "]"); } reader.register(ClassUtils.toClassArray(this.annotatedClasses)); } if (!this.basePackages.isEmpty()) { if (logger.isDebugEnabled()) { logger.debug("Scanning base packages: [" + StringUtils.collectionToCommaDelimitedString(this.basePackages) + "]"); } scanner.scan(StringUtils.toStringArray(this.basePackages)); } String[] configLocations = getConfigLocations(); if (configLocations != null) { for (String configLocation : configLocations) { try { Class<?> clazz = ClassUtils.forName(configLocation, getClassLoader()); if (logger.isTraceEnabled()) { logger.trace("Registering [" + configLocation + "]"); } reader.register(clazz); } catch (ClassNotFoundException ex) { if (logger.isTraceEnabled()) { logger.trace("Could not load class for config location [" + configLocation + "] - trying package scan. " + ex); } int count = scanner.scan(configLocation); if (count == 0 && logger.isDebugEnabled()) { logger.debug("No annotated classes found for specified class/package [" + configLocation + "]"); } } } } }
Example 6
Source File: AnnotationConfigWebApplicationContext.java From java-technology-stack with MIT License | 4 votes |
/** * Register a {@link org.springframework.beans.factory.config.BeanDefinition} for * any classes specified by {@link #register(Class...)} and scan any packages * specified by {@link #scan(String...)}. * <p>For any values specified by {@link #setConfigLocation(String)} or * {@link #setConfigLocations(String[])}, attempt first to load each location as a * class, registering a {@code BeanDefinition} if class loading is successful, * and if class loading fails (i.e. a {@code ClassNotFoundException} is raised), * assume the value is a package and attempt to scan it for annotated classes. * <p>Enables the default set of annotation configuration post processors, such that * {@code @Autowired}, {@code @Required}, and associated annotations can be used. * <p>Configuration class bean definitions are registered with generated bean * definition names unless the {@code value} attribute is provided to the stereotype * annotation. * @param beanFactory the bean factory to load bean definitions into * @see #register(Class...) * @see #scan(String...) * @see #setConfigLocation(String) * @see #setConfigLocations(String[]) * @see AnnotatedBeanDefinitionReader * @see ClassPathBeanDefinitionScanner */ @Override protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) { AnnotatedBeanDefinitionReader reader = getAnnotatedBeanDefinitionReader(beanFactory); ClassPathBeanDefinitionScanner scanner = getClassPathBeanDefinitionScanner(beanFactory); BeanNameGenerator beanNameGenerator = getBeanNameGenerator(); if (beanNameGenerator != null) { reader.setBeanNameGenerator(beanNameGenerator); scanner.setBeanNameGenerator(beanNameGenerator); beanFactory.registerSingleton(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR, beanNameGenerator); } ScopeMetadataResolver scopeMetadataResolver = getScopeMetadataResolver(); if (scopeMetadataResolver != null) { reader.setScopeMetadataResolver(scopeMetadataResolver); scanner.setScopeMetadataResolver(scopeMetadataResolver); } if (!this.annotatedClasses.isEmpty()) { if (logger.isDebugEnabled()) { logger.debug("Registering annotated classes: [" + StringUtils.collectionToCommaDelimitedString(this.annotatedClasses) + "]"); } reader.register(ClassUtils.toClassArray(this.annotatedClasses)); } if (!this.basePackages.isEmpty()) { if (logger.isDebugEnabled()) { logger.debug("Scanning base packages: [" + StringUtils.collectionToCommaDelimitedString(this.basePackages) + "]"); } scanner.scan(StringUtils.toStringArray(this.basePackages)); } String[] configLocations = getConfigLocations(); if (configLocations != null) { for (String configLocation : configLocations) { try { Class<?> clazz = ClassUtils.forName(configLocation, getClassLoader()); if (logger.isTraceEnabled()) { logger.trace("Registering [" + configLocation + "]"); } reader.register(clazz); } catch (ClassNotFoundException ex) { if (logger.isTraceEnabled()) { logger.trace("Could not load class for config location [" + configLocation + "] - trying package scan. " + ex); } int count = scanner.scan(configLocation); if (count == 0 && logger.isDebugEnabled()) { logger.debug("No annotated classes found for specified class/package [" + configLocation + "]"); } } } } }
Example 7
Source File: AnnotationConfigWebApplicationContext.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Register a {@link org.springframework.beans.factory.config.BeanDefinition} for * any classes specified by {@link #register(Class...)} and scan any packages * specified by {@link #scan(String...)}. * <p>For any values specified by {@link #setConfigLocation(String)} or * {@link #setConfigLocations(String[])}, attempt first to load each location as a * class, registering a {@code BeanDefinition} if class loading is successful, * and if class loading fails (i.e. a {@code ClassNotFoundException} is raised), * assume the value is a package and attempt to scan it for annotated classes. * <p>Enables the default set of annotation configuration post processors, such that * {@code @Autowired}, {@code @Required}, and associated annotations can be used. * <p>Configuration class bean definitions are registered with generated bean * definition names unless the {@code value} attribute is provided to the stereotype * annotation. * @param beanFactory the bean factory to load bean definitions into * @see #register(Class...) * @see #scan(String...) * @see #setConfigLocation(String) * @see #setConfigLocations(String[]) * @see AnnotatedBeanDefinitionReader * @see ClassPathBeanDefinitionScanner */ @Override protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) { AnnotatedBeanDefinitionReader reader = getAnnotatedBeanDefinitionReader(beanFactory); ClassPathBeanDefinitionScanner scanner = getClassPathBeanDefinitionScanner(beanFactory); BeanNameGenerator beanNameGenerator = getBeanNameGenerator(); if (beanNameGenerator != null) { reader.setBeanNameGenerator(beanNameGenerator); scanner.setBeanNameGenerator(beanNameGenerator); beanFactory.registerSingleton(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR, beanNameGenerator); } ScopeMetadataResolver scopeMetadataResolver = getScopeMetadataResolver(); if (scopeMetadataResolver != null) { reader.setScopeMetadataResolver(scopeMetadataResolver); scanner.setScopeMetadataResolver(scopeMetadataResolver); } if (!this.annotatedClasses.isEmpty()) { if (logger.isInfoEnabled()) { logger.info("Registering annotated classes: [" + StringUtils.collectionToCommaDelimitedString(this.annotatedClasses) + "]"); } reader.register(this.annotatedClasses.toArray(new Class<?>[this.annotatedClasses.size()])); } if (!this.basePackages.isEmpty()) { if (logger.isInfoEnabled()) { logger.info("Scanning base packages: [" + StringUtils.collectionToCommaDelimitedString(this.basePackages) + "]"); } scanner.scan(this.basePackages.toArray(new String[this.basePackages.size()])); } String[] configLocations = getConfigLocations(); if (configLocations != null) { for (String configLocation : configLocations) { try { Class<?> clazz = getClassLoader().loadClass(configLocation); if (logger.isInfoEnabled()) { logger.info("Successfully resolved class for [" + configLocation + "]"); } reader.register(clazz); } catch (ClassNotFoundException ex) { if (logger.isDebugEnabled()) { logger.debug("Could not load class for config location [" + configLocation + "] - trying package scan. " + ex); } int count = scanner.scan(configLocation); if (logger.isInfoEnabled()) { if (count == 0) { logger.info("No annotated classes found for specified class/package [" + configLocation + "]"); } else { logger.info("Found " + count + " annotated classes in package [" + configLocation + "]"); } } } } } }
Example 8
Source File: AnnotationConfigWebApplicationContext.java From spring4-understanding with Apache License 2.0 | 4 votes |
/** * Register a {@link org.springframework.beans.factory.config.BeanDefinition} for * any classes specified by {@link #register(Class...)} and scan any packages * specified by {@link #scan(String...)}. * <p>For any values specified by {@link #setConfigLocation(String)} or * {@link #setConfigLocations(String[])}, attempt first to load each location as a * class, registering a {@code BeanDefinition} if class loading is successful, * and if class loading fails (i.e. a {@code ClassNotFoundException} is raised), * assume the value is a package and attempt to scan it for annotated classes. * <p>Enables the default set of annotation configuration post processors, such that * {@code @Autowired}, {@code @Required}, and associated annotations can be used. * <p>Configuration class bean definitions are registered with generated bean * definition names unless the {@code value} attribute is provided to the stereotype * annotation. * @param beanFactory the bean factory to load bean definitions into * @see #register(Class...) * @see #scan(String...) * @see #setConfigLocation(String) * @see #setConfigLocations(String[]) * @see AnnotatedBeanDefinitionReader * @see ClassPathBeanDefinitionScanner */ @Override protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) { AnnotatedBeanDefinitionReader reader = getAnnotatedBeanDefinitionReader(beanFactory); ClassPathBeanDefinitionScanner scanner = getClassPathBeanDefinitionScanner(beanFactory); BeanNameGenerator beanNameGenerator = getBeanNameGenerator(); if (beanNameGenerator != null) { reader.setBeanNameGenerator(beanNameGenerator); scanner.setBeanNameGenerator(beanNameGenerator); beanFactory.registerSingleton(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR, beanNameGenerator); } ScopeMetadataResolver scopeMetadataResolver = getScopeMetadataResolver(); if (scopeMetadataResolver != null) { reader.setScopeMetadataResolver(scopeMetadataResolver); scanner.setScopeMetadataResolver(scopeMetadataResolver); } if (!this.annotatedClasses.isEmpty()) { if (logger.isInfoEnabled()) { logger.info("Registering annotated classes: [" + StringUtils.collectionToCommaDelimitedString(this.annotatedClasses) + "]"); } reader.register(this.annotatedClasses.toArray(new Class<?>[this.annotatedClasses.size()])); } if (!this.basePackages.isEmpty()) { if (logger.isInfoEnabled()) { logger.info("Scanning base packages: [" + StringUtils.collectionToCommaDelimitedString(this.basePackages) + "]"); } scanner.scan(this.basePackages.toArray(new String[this.basePackages.size()])); } String[] configLocations = getConfigLocations(); if (configLocations != null) { for (String configLocation : configLocations) { try { Class<?> clazz = getClassLoader().loadClass(configLocation); if (logger.isInfoEnabled()) { logger.info("Successfully resolved class for [" + configLocation + "]"); } reader.register(clazz); } catch (ClassNotFoundException ex) { if (logger.isDebugEnabled()) { logger.debug("Could not load class for config location [" + configLocation + "] - trying package scan. " + ex); } int count = scanner.scan(configLocation); if (logger.isInfoEnabled()) { if (count == 0) { logger.info("No annotated classes found for specified class/package [" + configLocation + "]"); } else { logger.info("Found " + count + " annotated classes in package [" + configLocation + "]"); } } } } } }
Example 9
Source File: AnnotationConfigWebApplicationContext.java From elasticactors with Apache License 2.0 | 4 votes |
/** * Register a {@link org.springframework.beans.factory.config.BeanDefinition} for * any classes specified by {@link #register(Class...)} and scan any packages * specified by {@link #scan(String...)}. * <p>For any values specified by {@link #setConfigLocation(String)} or * {@link #setConfigLocations(String[])}, attempt first to load each location as a * class, registering a {@code BeanDefinition} if class loading is successful, * and if class loading fails (i.e. a {@code ClassNotFoundException} is raised), * assume the value is a package and attempt to scan it for annotated classes. * <p>Enables the default set of annotation configuration post processors, such that * {@code @Autowired}, {@code @Required}, and associated annotations can be used. * <p>Configuration class bean definitions are registered with generated bean * definition names unless the {@code value} attribute is provided to the stereotype * annotation. * @see #register(Class...) * @see #scan(String...) * @see #setConfigLocation(String) * @see #setConfigLocations(String[]) * @see AnnotatedBeanDefinitionReader * @see ClassPathBeanDefinitionScanner */ @Override protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) { AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(beanFactory); reader.setEnvironment(this.getEnvironment()); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(beanFactory); scanner.setEnvironment(this.getEnvironment()); BeanNameGenerator beanNameGenerator = getBeanNameGenerator(); ScopeMetadataResolver scopeMetadataResolver = getScopeMetadataResolver(); if (beanNameGenerator != null) { reader.setBeanNameGenerator(beanNameGenerator); scanner.setBeanNameGenerator(beanNameGenerator); beanFactory.registerSingleton( AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR, beanNameGenerator); } if (scopeMetadataResolver != null) { reader.setScopeMetadataResolver(scopeMetadataResolver); scanner.setScopeMetadataResolver(scopeMetadataResolver); } if (!this.annotatedClasses.isEmpty()) { if (logger.isInfoEnabled()) { logger.info("Registering annotated classes: [" + StringUtils.collectionToCommaDelimitedString(this.annotatedClasses) + "]"); } reader.register(this.annotatedClasses.toArray(new Class<?>[0])); } if (!this.basePackages.isEmpty()) { if (logger.isInfoEnabled()) { logger.info("Scanning base packages: [" + StringUtils.collectionToCommaDelimitedString(this.basePackages) + "]"); } for (TypeFilter typeFilter : includeFilters) { scanner.addIncludeFilter(typeFilter); } scanner.scan(this.basePackages.toArray(new String[0])); } String[] configLocations = getConfigLocations(); if (configLocations != null) { for (String configLocation : configLocations) { try { Class<?> clazz = getClassLoader().loadClass(configLocation); if (logger.isInfoEnabled()) { logger.info("Successfully resolved class for [" + configLocation + "]"); } reader.register(clazz); } catch (ClassNotFoundException ex) { if (logger.isDebugEnabled()) { logger.debug("Could not load class for config location [" + configLocation + "] - trying package scan. " + ex); } int count = scanner.scan(configLocation); if (logger.isInfoEnabled()) { if (count == 0) { logger.info("No annotated classes found for specified class/package [" + configLocation + "]"); } else { logger.info("Found " + count + " annotated classes in package [" + configLocation + "]"); } } } } } }