First Spring Boot (DI)

Introduction

As a new graduate, I entered a web-based company and started training. As part of that, there was training using Spring Boot, so I would like to keep it as a memorandum. This is my first post on Qiita, so I hope you can see it with warm eyes. We welcome your suggestions, so please comment if you like.

DI(Dependency Injection) A type of design pattern (design concept). It seems to mean the injection of dependency. What will happen

Sample.java


Test test;
Sample(){
 test = new Test();
}

This looks like below

Sample.java


Test test;
Sample(Test test){
 this.test = test;
}

--There is a difference between creating an instance yourself and receiving what you create. --The instance is this test. --This has the advantage that it can be developed even if the Test class is not created. ――Honestly, it's a field that I didn't really get into the development site.

Reference: Difference between class and instance Reference: A brief description of Spring DI and AOP

DI container

When trying to implement DI

--The amount of code is likely to increase because you have to create a lot of instances at the caller. --So appeared ** DI container ** --DI container automatically injects instances

With DI container

Sample.java


Test1 test1;
Test2 test2;
Test3 test3;
Sample(Test1 test1,Test2 test2,Test3 test3){
 this.test1 = test1;
 this.test2 = test2;
 this.test3 = test3;
}

This looks like below

Sample.java


@Autowired
Test1 test1;
@Autowired
Test2 test2;
@Autowired
Test3 test3;

When actually using it, it is necessary to annotate each class file. For details on how to use it, click here [https://qiita.com/shuntaro_tamura/items/ba5a2e9b3ba305285edd)

Summary

This time I posted it as a practice of qiita. I'm still immature because I'm a new graduate, From now on, I would like to gradually increase the output and improve the quality.

Recommended Posts

First Spring Boot (DI)
Introduction to Spring Boot ① ~ DI ~
Spring Boot for the first time
Challenge Spring Boot
Spring Boot Form
Spring Boot Memorandum
gae + spring boot
[Java] Spring DI ③
DI SessionScope Bean in Spring Boot 2 Filter
SPRING BOOT learning record 01
Spring Boot + Heroku Postgres
Spring Framework Summary-About DI
Spring boot memo writing (1)
About DI of Spring ①
SPRING BOOT learning record 02
Spring Boot2 cheat sheet
Spring Boot exception handling
Spring Boot Servlet mapping
Spring boot development-development environment-
Spring Boot learning procedure
About DI of Spring ②
Learning Spring Boot [Beginning]
Spring boot memo writing (2)
Spring Boot 2.2 Document Summary
[Spring Boot] DataSourceProperties $ DataSourceBeanCreationException
Spring Boot 2.3 Application Availability
Spring boot tutorials Topics
Spring Basics ~ DI Edition ~
Download with Spring Boot
Try using DI container with Laravel and Spring Boot
How to set Dependency Injection (DI) for Spring Boot
[Spring boot] I thought about testable code by DI
[Spring Boot] Environment construction (macOS)
Set context-param in Spring Boot
Try Spring Boot from 0 to 100.
Generate barcode with Spring Boot
Hello World with Spring Boot
Spring Boot on Microsoft Azure
Spring Boot tutorial task schedule
Spring 5 & Spring Boot 2 Hands-on preparation procedure
Get started with Spring boot
Hello World with Spring Boot!
Spring Boot 2 multi-project in Gradle
[Spring Boot] Web application creation
spring boot port duplication problem
Run LIFF with Spring Boot
SNS login with Spring Boot
Spring Boot Hot Swapping settings
[Java] Thymeleaf Basic (Spring Boot)
File upload with Spring Boot
Spring Boot starting with copy
Introduction to Spring Boot ② ~ AOP ~
CICS-Run Java application-(4) Spring Boot application
Spring Boot starting with Docker
Spring Boot + Springfox springfox-boot-starter 3.0.0 Use
Spring Boot DB related tips
Hello World with Spring Boot
Set cookies with Spring Boot
[Java] How Spring DI works
[Spring Boot] Easy paging recipe
Use Spring JDBC with Spring Boot