How to split a bloated Java Config.
Load the split subclass with @ org.springframework.context.annotation.Import
.
AppConfig.java
@Configuration
@Import({SubConfig.class, Sub2Config.class})
public class AppConfig {
// subConfig.class, sub2Config.Bean defined in class is injected
}
Add @Configuration
SubConfig.java
@Configuration
public class SubConfig {
@Bean
UserService userService() {
//・ ・ ・
}
}
Sub2Config.java
@Configuration
public class Sub2Config {
@Bean
ShopService shopService() {
//・ ・ ・
}
}
Recommended Posts