jfzr
jfzr

Reputation: 395

Load entire folder of Java Configuration files?

Is there any way to load a entire folder with @Configuration files, the same way XML have: <import resource="folder/*.xml" />, but with annotations?.

Upvotes: 0

Views: 524

Answers (2)

Nicolas Labrot
Nicolas Labrot

Reputation: 4106

The pendant of <import resource="folder/*.xml" /> but using configuration is @ImportResource

For example:

@Configuration
@ImportResource("folder/*.xml")
public class MyConfiguration {}

Upvotes: 2

Prometheus
Prometheus

Reputation: 1015

You could probably use component scanning.

@Configuration
@ComponentScan(basePackages = "org.example.configs")
public class Config {
}

All @Configuration classes from the org.example.configs package will be included in the context.

Typesafe alternative:

// org.example.configs.SubConfig
@ComponentScan(basePackageClasses = SubConfig.class)

Upvotes: 1

Related Questions