[JAVA] [Spring Framework] Configuration split

Configuration split

How to split a bloated Java Config.

Java Config split

Main class

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
}

Divided subclass

Add @Configuration

SubConfig.java


@Configuration
public class SubConfig {
  @Bean
  UserService userService() {
  //・ ・ ・
  }
}

Sub2Config.java


@Configuration
public class Sub2Config {
  @Bean
  ShopService shopService() {
  //・ ・ ・
  }
}

Recommended Posts

[Spring Framework] Configuration split
Spring Framework multilingual support
1. Start Spring framework from 1
Spring Framework Summary-About DI
[Personal memo] About Spring framework
Spring Framework self-study memo series_1
About Spring Framework context error
Minimum configuration sample of RESTful API in Jersey + Spring Framework
Spring Framework 5.0 Summary of major changes
spring framework Simple study memo (2): AOP
Java --Jersey Framework vs Spring Boot
How to set and use profile in annotation-based Configuration in Spring framework
Spring Framework tools for Java developer
Test Spring framework controller with Junit
Introducing Basic Authentication on Heroku [Spring Framework]
Major changes related to Spring Framework 5.0 Test
Spring Framework bean definition XML: custom tag
Why spring consider as a lightweight framework
Spring Framework study notes [Part 1] DI container
About the initial display of Spring Framework
Major changes in Spring Framework 5.0 core functionality
Features of spring framework for java developers
How to split Spring Boot message file
Maven configuration problem in Spring pom.xml in Eclipse