Autowire Annotation in Spring without using Component Scanning

autowired, dependency-injection, ioc-container, spring

Solution

Yes. `<context-component-scan .. />` is responsible for discovering beans annotated with `@Component`, `@Controller`, `@Service`, `@Respository`, etc.

In order to have annotations processed (`@Autowired`, `@Resource`, etc) you need `<context:annotation-config />`. Thus annotations are processed on beans that are listed in `applicationContext.xml`.

As far as I know, `<context-component-scan .. />` activates `<context:annotation-config />` automatically.

This is true for both spring 2.5 and 3.0. (thanks skaffman)

Problem

Is it possible to autowire beans using the `@Autowired` annotation without using component scanning?

Original source

Related problems