Dependency Injection
@Resource | Annotation used to inject an object that is already in the Application Context. It searches the instance by name. It also works on setter methods. |
---|---|
@Autowired | Annotation used to inject objects in many possible ways, such as: instance variable, constructor and methods. It does not rely on name as @Resource , so, for multiple concrete implementations, the @Qualifier annotation must be used with it. |
@Qualifier | Annotation used to distinguish between multiple concrete implementations. Used alongside with @Autowired annotation that does not rely on name. |
@Primary | Annotation used when no name is provided telling Spring to inject an object of the annotated class first. Used along with @Component . |
@Component | Generic stereotype annotation used to tell Spring to create an instance of the object in the Application Context. It's possible to define any name for the instance, the default is the class name as camel case. |
@Controller | Stereotype annotation for presentation layer. |
@Repository | Stereotype annotation for persistence layer. |
@Service |
Modules
Spring MVC
|
Spring Properties Evaluation Sequence
Command-line arguments
| java -Dproject.name=Test -jar app.jar |
System properties
| System.getProperties() |
Environment Variable
| export PROJECT_NAME=Test |
External properties/yml file
| project.name=Test |
Internal properties/yml file
| project.name=Test |
Spring Boot Bootstrapped Annotations
@SpringBootApplication
|
Initial annotation that comprises the following annotations:
@SpringBootConfiguration , @EnableAutoConfiguration and @ComponentScan . |
@SpringBootConfiguration
|
Indicates that a class provides Spring Boot application
@Configuration . |
@EnableAutoConfiguration
|
Enable auto-configuration of the Spring Application Context, attempting to guess and configure beans that you are likely to need.
|
@ComponentScan
|
Configures component scanning directives for use with
@Configuration classes. |