ConfigurationClassParser detects @Bean methods in interface hierarchies as well
Issue: SPR-14288
(cherry picked from commit 03affa0
)
This commit is contained in:
parent
7de2976c1e
commit
62199e82ef
|
@ -295,15 +295,7 @@ class ConfigurationClassParser {
|
|||
}
|
||||
|
||||
// Process default methods on interfaces
|
||||
for (SourceClass ifc : sourceClass.getInterfaces()) {
|
||||
beanMethods = ifc.getMetadata().getAnnotatedMethods(Bean.class.getName());
|
||||
for (MethodMetadata methodMetadata : beanMethods) {
|
||||
if (!methodMetadata.isAbstract()) {
|
||||
// A default method or other concrete method on a Java 8+ interface...
|
||||
configClass.addBeanMethod(new BeanMethod(methodMetadata, configClass));
|
||||
}
|
||||
}
|
||||
}
|
||||
processInterfaces(configClass, sourceClass);
|
||||
|
||||
// Process superclass, if any
|
||||
if (sourceClass.getMetadata().hasSuperClass()) {
|
||||
|
@ -321,8 +313,6 @@ class ConfigurationClassParser {
|
|||
|
||||
/**
|
||||
* Register member (nested) classes that happen to be configuration classes themselves.
|
||||
* @param sourceClass the source class to process
|
||||
* @throws IOException if there is any problem reading metadata from a member class
|
||||
*/
|
||||
private void processMemberClasses(ConfigurationClass configClass, SourceClass sourceClass) throws IOException {
|
||||
for (SourceClass memberClass : sourceClass.getMemberClasses()) {
|
||||
|
@ -344,6 +334,22 @@ class ConfigurationClassParser {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register default methods on interfaces implemented by the configuration class.
|
||||
*/
|
||||
private void processInterfaces(ConfigurationClass configClass, SourceClass sourceClass) throws IOException {
|
||||
for (SourceClass ifc : sourceClass.getInterfaces()) {
|
||||
Set<MethodMetadata> beanMethods = ifc.getMetadata().getAnnotatedMethods(Bean.class.getName());
|
||||
for (MethodMetadata methodMetadata : beanMethods) {
|
||||
if (!methodMetadata.isAbstract()) {
|
||||
// A default method or other concrete method on a Java 8+ interface...
|
||||
configClass.addBeanMethod(new BeanMethod(methodMetadata, configClass));
|
||||
}
|
||||
}
|
||||
processInterfaces(configClass, ifc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the given <code>@PropertySource</code> annotation metadata.
|
||||
* @param propertySource metadata for the <code>@PropertySource</code> annotation found
|
||||
|
|
|
@ -1063,17 +1063,27 @@ public class ConfigurationClassPostProcessorTests {
|
|||
}
|
||||
}
|
||||
|
||||
public interface DefaultMethodsConfig {
|
||||
public interface BaseInterface {
|
||||
|
||||
@Bean
|
||||
default ServiceBean serviceBean() {
|
||||
return provider().getServiceBean();
|
||||
}
|
||||
ServiceBean serviceBean();
|
||||
}
|
||||
|
||||
public interface BaseDefaultMethods extends BaseInterface {
|
||||
|
||||
@Bean
|
||||
default ServiceBeanProvider provider() {
|
||||
return new ServiceBeanProvider();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Override
|
||||
default ServiceBean serviceBean() {
|
||||
return provider().getServiceBean();
|
||||
}
|
||||
}
|
||||
|
||||
public interface DefaultMethodsConfig extends BaseDefaultMethods {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
|
Loading…
Reference in New Issue