ConfigurationClassParser detects @Bean methods in interface hierarchies as well
Issue: SPR-14288
This commit is contained in:
parent
2d85accb83
commit
03affa02db
|
@ -303,15 +303,7 @@ class ConfigurationClassParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process default methods on interfaces
|
// Process default methods on interfaces
|
||||||
for (SourceClass ifc : sourceClass.getInterfaces()) {
|
processInterfaces(configClass, sourceClass);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process superclass, if any
|
// Process superclass, if any
|
||||||
if (sourceClass.getMetadata().hasSuperClass()) {
|
if (sourceClass.getMetadata().hasSuperClass()) {
|
||||||
|
@ -329,8 +321,6 @@ class ConfigurationClassParser {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register member (nested) classes that happen to be configuration classes themselves.
|
* 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 {
|
private void processMemberClasses(ConfigurationClass configClass, SourceClass sourceClass) throws IOException {
|
||||||
for (SourceClass memberClass : sourceClass.getMemberClasses()) {
|
for (SourceClass memberClass : sourceClass.getMemberClasses()) {
|
||||||
|
@ -352,6 +342,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.
|
* Process the given <code>@PropertySource</code> annotation metadata.
|
||||||
* @param propertySource metadata for the <code>@PropertySource</code> annotation found
|
* @param propertySource metadata for the <code>@PropertySource</code> annotation found
|
||||||
|
|
|
@ -1063,17 +1063,27 @@ public class ConfigurationClassPostProcessorTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface DefaultMethodsConfig {
|
public interface BaseInterface {
|
||||||
|
|
||||||
@Bean
|
ServiceBean serviceBean();
|
||||||
default ServiceBean serviceBean() {
|
|
||||||
return provider().getServiceBean();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface BaseDefaultMethods extends BaseInterface {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
default ServiceBeanProvider provider() {
|
default ServiceBeanProvider provider() {
|
||||||
return new ServiceBeanProvider();
|
return new ServiceBeanProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Override
|
||||||
|
default ServiceBean serviceBean() {
|
||||||
|
return provider().getServiceBean();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface DefaultMethodsConfig extends BaseDefaultMethods {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
|
Loading…
Reference in New Issue