ComponentScan annotation allows for registering beans with lazy initialization
Issue: SPR-10459
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -163,6 +163,14 @@ public class ClassPathBeanDefinitionScanner extends ClassPathScanningCandidateCo
|
||||
(beanDefinitionDefaults != null ? beanDefinitionDefaults : new BeanDefinitionDefaults());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the defaults to use for detected beans (never {@code null}).
|
||||
* @since 4.1
|
||||
*/
|
||||
public BeanDefinitionDefaults getBeanDefinitionDefaults() {
|
||||
return this.beanDefinitionDefaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name-matching patterns for determining autowire candidates.
|
||||
* @param autowireCandidatePatterns the patterns to match against
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -132,6 +132,13 @@ public @interface ComponentScan {
|
||||
*/
|
||||
Filter[] excludeFilters() default {};
|
||||
|
||||
/**
|
||||
* Specify whether scanned beans should be registered for lazy initialization.
|
||||
* <p>Default is {@code false}; switch this to {@code true} when desired.
|
||||
* @since 4.1
|
||||
*/
|
||||
boolean lazyInit() default false;
|
||||
|
||||
|
||||
/**
|
||||
* Declares the type filter to be used as an {@linkplain ComponentScan#includeFilters()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -106,6 +106,11 @@ class ComponentScanAnnotationParser {
|
||||
}
|
||||
}
|
||||
|
||||
boolean lazyInit = componentScan.getBoolean("lazyInit");
|
||||
if (lazyInit) {
|
||||
scanner.getBeanDefinitionDefaults().setLazyInit(true);
|
||||
}
|
||||
|
||||
List<String> basePackages = new ArrayList<String>();
|
||||
for (String pkg : componentScan.getStringArray("value")) {
|
||||
if (StringUtils.hasText(pkg)) {
|
||||
|
||||
Reference in New Issue
Block a user