Spring boot to load list of packages from properties file

pokken :

I have project setup using Spring boot that loads individual components on startup. Each individual packages contain its own datasource, processes, etc. I can simply use this and it works fine

@SpringBootApplication(scanBasePackages = {
    "com.package1",
    "com.package2",
    "com.package3"
})
public class Application extends SpringBootServletInitializer{
    public static void main(String[] args){
        SpringApplication.run(Application.class,args)        
    }
}

But currently, the number of indiviual projects are getting bigger. Is it possible to put the list of the components / packages to scan in an external properties file or spring vault? I'm not sure how to retrieve it, and is it possible to retrieve the properties before the boot?


Edit:

Currently I tried this:

@Import(AppConfig.class)
public class Application extends SpringBootServletInitializer{
    public static void main(String[] args){
        SpringApplication.run(Application.class,args)        
    }
}


@Configuration
@ComponentScan(basePackages = {$app.packages})
@EnableAutoConfiguration
public class AppConfig {
}

//in my properties file
app.packages = ["com.package1","com.package2","com.package3"]

but its not working

Deadpool :

You are on right track but couple of minor mistakes, specify the packages by common separated in yml or properties file

app.packages = com.package1,com.package2,com.package3

Then use Spring Expression Language in @ComponentScan annotation

@ComponentScan(basePackages = {"${app.packages}"})

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=130270&siteId=1