최대 1 분 소요

Overview

In this Spring Framework tutorial, you’ll demonstrate how to use annotations related to dependency injection, namely the @Resource@Inject, and @Autowired annotations. These annotations provide classes with a declarative way to resolve dependencies:

@Autowired 
ArbitraryClass arbObject;

As opposed to instantiating them directly (the imperative way):

ArbitraryClass arbObject = new ArbitraryClass();

Two of the three annotations belong to the Java extension package: javax.annotation.Resource and javax.inject.Inject. The @Autowired annotation belongs to the org.springframework.beans.factory.annotation package.

Each of these annotations can resolve dependencies either by field injection or by setter injection. You will use a simplified, but practical example to demonstrate the distinction between the three annotations, based on the execution paths taken by each annotation.

The examples will focus on how to use the three injection annotations during integration testing. The dependency required by the test can either be an arbitrary file or an arbitrary class.

태그:

카테고리:

업데이트:

댓글남기기