blue note
blue note

Reputation: 29081

Spring: annotation-config base-package

In spring configuration <context:component-scan> supports a base-package attribute to limit it classpath search. However, <context:annotation-config> does not seem to have a similar attribute. What's more, component scan implicitly enables annotation config. However, that seems to mean that by enabling component scanning in just one package of the project I have to enable annotation scanning in the whole project. Is that true, and if so, can it be avoided?

Upvotes: 0

Views: 633

Answers (1)

codependent
codependent

Reputation: 24452

Using <context:component-scan base-package="com.org.pkg1"/> doesn't imply that you are

enabling annotation scanning in the whole project

It's true that <context:component-scan> also enables <context:annotation-config>. But the latter only allows the recognition of annotations in the already registered beans (no matter if they come from a scan or from XML).

Answering your question:

Is that true, and if so, can it be avoided

No.

This is the official doc for annotation-scanning:

Activates various annotations to be detected in bean classes: Spring's @Required and @Autowired, as well as JSR 250's @PostConstruct, @PreDestroy and @Resource (if available), JAX-WS's @WebServiceRef (if available), EJB 3's @EJB (if available), and JPA's @PersistenceContext and @PersistenceUnit

Upvotes: 1

Related Questions