0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Spring Framework]Configurationの分割

Posted at

Configurationの分割

肥大化したJava Configを分割する方法です。

Java Configの分割

メインクラス

分割したサブクラスを@org.springframework.context.annotation.Importで読み込む。

AppConfig.java
@Configuration
@Import({SubConfig.class, Sub2Config.class})
public class AppConfig {
  // subConfig.class, sub2Config.classに定義したBeanがインジェクションされる
}

分割したサブクラス

@Configurationをつける

SubConfig.java
@Configuration
public class SubConfig {
  @Bean
  UserService userService() {
  // ・・・
  }
}
Sub2Config.java
@Configuration
public class Sub2Config {
  @Bean
  ShopService shopService() {
  // ・・・
  }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?