itat
itat

Reputation: 1

What will happen when I add multiple @ComponentScan in different @Configuration class

When using spring, I want to have a configuration structure like:

//package com.test
//main configuration A
@Configuration
@ComponentScan({"com.pakcage.A", "com.common"})
public class AppA{
...
}

//package com.test
//main configuration B
@Configuration
@ComponentScan({"com.pakcage.B", "com.common"})
public class AppB{
...
}

//package com.common
//sub configuration for common use
@Configuration
@ComponentScan({"com.pakcage.common1", "com.package.common2"})
public class CommonConfig{
...
}

I can launch my Application by useing Configuration AppA or Configuration AppB, and all of them contains some common packages to scan like

"com.pakcage.common1"/"com.package.common2"

, I want to put it into a single configuration.

I want to ask

  1. What will happen when I put multiply @ComponentScan, there will be a combination of all of these @ComponenScan?
  2. Is there some source code reference to read about how this happen?

Upvotes: 0

Views: 79

Answers (1)

user10367961
user10367961

Reputation:

  1. Yes, all the packages defined by any @ComponentScan will be scanned.
  2. Yes, spring framework is opensource. You can access the sources here.

Upvotes: 2

Related Questions