2

Hi I created one custom auto configuration library as following:

@Configuration
@EnableConfigurationProperties(RefreshProperties.class)
public class PropertiesRefresherAutoConfiguration {
    public static final String AUTO_REFRESH_ENABLED = RefreshProperties.PROPERTIES_AUTO_REFRESH + ".enabled";

    @ConditionalOnProperty(
            name = PropertiesRefresherAutoConfiguration.AUTO_REFRESH_ENABLED,
            havingValue = "true"
    )
    @Bean
    public Refresher getRefresher(){
        return new Refresher();
    }
    
}

I have added spring.factories in META-INF with content:

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.bla.PropertiesRefresherAutoConfiguration

What I want to achieve is when I use dependency of this custom library and I set application.yaml properties:

properties:
  refresh:
    enabled: true

Refresher instance should automatically be created. In Refresher class there is one method that should be called on application start

@PostConstruct
public void startTask() {
  //do something
}

In my main application I've added dependency to it and defined properties in application.yaml but Refresher Bean is not created and startTask() method is not called

I have tried to remove @Conditional annotation in order to create instance of Refresh every time, but that didn't help.

scorpion
  • 21
  • 3
  • 2
    If you use spring-boot **3** have a look here: [unable-to-create-custom-spring-boot-starter-autoconfiguration](https://stackoverflow.com/questions/75313425/unable-to-create-custom-spring-boot-starter-autoconfiguration/75314073#75314073) – Dirk Deyne Feb 15 '23 at 16:03
  • Yes i am using spring boot 3. Thanks i will try that. – scorpion Feb 15 '23 at 17:23

0 Answers0