### 不需要創建對象
### 而是被注入
### 配置更加方便
### 更加靈活
### 測試更加簡單
`@Autowired` 注解用于依賴注入
* 構造器
* 屬性
* 字段
例如:
```java
public class SimpleService {
@Autowired
SimpleRepository repository;
public DomainObject service() {
return repository.findDomainObject();
}
}
```
依賴注入操作的對象是 Spring Bean,使用注解標注 Bean,例如:
```
@Service
public class SimpleService {
@Autowired
SimpleRepository repository;
...
}
```
```
@Repository
public class SimpleRepository {
...
}
```
如何測試 Spring 應用? 使用 `@RunWith` 配合 `@ContextConfiguration` 定義的配置文件。