roger
roger

Reputation: 269

Spring @ComponentScan annotation

Why do we use @ComponentScan annotation in spring ? I am not being able to figure out the exact difference between context:componentscan in xml file and @ComponentScan annotations in java and how to use them in case of classes which have been annotated with @Configuration

Upvotes: 1

Views: 1194

Answers (2)

Razib
Razib

Reputation: 11153

But there is one advantage of xml based configuration - you don't need to compile your java code. When you added some package under <context:component-scan> then you don't need to compile java source code. Place the xml configuration file in your server and restart it.

Upvotes: 0

vtor
vtor

Reputation: 9309

In short, there is no difference.

@ComponentScan - Used with @Configuration classes, for example, when you have java-based configurations for Spring.

It provides support parallel with Spring XML's <context:component-scan> element. The purpose of those two are exactly the same - to scan spring components.

Upvotes: 1

Related Questions