Here is a simple code sample:
@Configuration(proxyBeanMethods = false)
public class FooAutoConfiguration {
@ConditionalOnBean(FooProperties.class)
@ConditionalOnMissingBean
@Bean
public FooService fooService(FooProperties fooProperties) {
return new FooService();
}
}
pom.xml
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
...
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>
While evaluator conditional of FooService
, It will be evaluated twice for OnBeanCondition
because the AnnotatedTypeMetadata.getAllAnnotationAttributes
returned value contains same className array org.springframework.boot.autoconfigure.condition.OnBeanCondition
.