Search code examples
spring-bootspring-annotations

@AutoConfigureAfter not working as desired


I have 3 spring-boot-starter projects

One of the autoconfiguration class has the following code:

@Configuration
@ConditionalOnClass(value = Config.class)
@AutoConfigureAfter(value = {FileGeneratorConfig.class, FileUploaderConfig.class})
public class JobConfig 

FileGeneratorConfig and FileUploaderConfig are also autoconfiguration classes.

I was expecting that beans created in FileUploaderConfig will be created first. So test this I had put a break point in the method that creates bean in JobConfig and FileUploaderConfig. But the break point hits JobConfig first which makes me believe that my @AutoConfigureAfter is not working. Is that the right assumption.

Also in FileUploaderConfig i have this:

@Bean
    FileUtilContainer fileUtilContainer(FileUtilContainerProperties fileUtilContainerProperties){
        return new FileUtilContainer(FileUtil.createDirectory(fileUtilContainerProperties.getArchive()),
                                     FileUtil.createDirectory(fileUtilContainerProperties.getWorking()),
                                     FileUtil.createDirectory(fileUtilContainerProperties.getConfirmation()), 
                                     FileUtil.createDirectory(fileUtilContainerProperties.getConfirmationProcessed()),
                                     FileUtil.createDirectory(fileUtilContainerProperties.getError()), 
                                     FileUtil.createDirectory(fileUtilContainerProperties.getErrorProcessed()));
    }

and FileUtilContainerProperties:

@Component
@ConfigurationProperties(prefix = "batch.letter.directory", ignoreUnknownFields = false)
public class FileUtilContainerProperties

but it is not creating FileUtilContainerProperties bean. Am I missing something here?


Solution

  • AutoConfigureAfter controls the order in which the configuration files are processed and their bean definitions are created. The order in which beans are created from those definitions is a separate concern and depends on, among other things, the dependencies that exist between your beans.