0

I could not find documentation on beans xml configuration so I ask here: Do the "base package" in

<context:component-scan base-package="" /> 

is conceptually the same package as in Java?

For example, in my src/main/java (project explorer view in Eclipse, flat package presentation), say I have 4 packages com.amazon, com.amazon.entities, com.amazon.services, com.amazon.repositories. In Navigator view I have just "amazon" folder, inside it I have 3 folders (entities, repositories, services) and one java class MyClass.java. So if I write "context:component-scan base-package="com.amazon"", what will be scanned? Just MyClass.java, or also everything inside (entities, repositories, services) sub-folders as well?

Grim
  • 1,938
  • 10
  • 56
  • 123
Vaidotas
  • 175
  • 1
  • 1
  • 11

1 Answers1

1

If you write this:

<context:component-scan base-package="com.amazon" />

Then everything in com.amazon package and all its subpackages (com.amazon.repositories, com.amazon.services, etc) will be scanned.

The relevant part here is the actual package of your classes not the way your IDE displays your hierarchy.

Bohuslav Burghardt
  • 33,626
  • 7
  • 114
  • 109
  • But java classes inside com.amazon.services will have declaration "package com.amazon.services" which is totally different from the "com.amazon" package? So why should they be scanned? Or is the search going through file system inside "amazon" folder? – Vaidotas Nov 16 '14 at 19:02
  • I mentioned that the scanning happens for subpackages of your base package too. So if a class is in `com.amazon.services` package then that package is a subpackage of `com.amazon` and therefore will be scanned. – Bohuslav Burghardt Nov 16 '14 at 19:05
  • http://stackoverflow.com/questions/13809713/java-package-in-package says that there is no such thing in java as subpackage. The only thing these packages share is the namespace, i.e. "import com.amazon.*" will import every class in com.amazon and in 3 "subpackages". But otherwise they are unrelated, isn't it? – Vaidotas Nov 16 '14 at 19:13
  • Packages in Java are not actually hierarchical according to the Java compiler, but people often treat them that way anyway, and the Spring framework also does so. – Jesper Nov 16 '14 at 22:02