[JAVA] Spring boot memo writing (2)


Business efficiency

What is a DI (Dependency injection) container?

** In a nutshell, it translates as "injecting an instance from outside, not a program" ** = "injecting a dependency".

** You can create and use an instance with an external function instead of using the new operator ** to create an instance in your program.

Spring Boot is designed with DI (Dependency Injection), which can reduce ** code dependencies **.

Beans that are instances of the class are stored in the DI container.

Calls between SpringBoot classes are executed by acquiring the beans registered in the DI container.

The standard bean registration method is as follows.

  1. Add `` `@ Bean``` to the method. The singleton of the class specified in the return value of the method is registered in the DI container.
  2. Add `` `@ Component``` to the class you want to register as a bean. A singleton of that class is registered in the DI container
  3. Bean registration of the class is done just by adding `@ RestController``` which is the API declaration and `@ Configurationt``` which is the environment class declaration.

When SpringBoot starts, the DI container will read the following packages specified by @ComponentScan.

/* demo.service and demo.Of the domain and [email protected] for component and DI registration
Classes granted/Register the method in the DI container as a bean.*/
		scopedProxy = ScopedProxyMode.TARGET_CLASS,
		basePackages = {"demo.service","demo.domain"}
public class SBDataBaseDemoApplication {
	public static void main(String[] args) {
		SpringApplication.run(SBDataBaseDemoApplication.class, args);

Main annotations for DI

@controllerUsed for controller layer classes. @restcontrollerUsed for webapi controller layer classes.@controllerWhen@responsebodyIt is a combination of. @serviceUsed for service layer classes. Mainly used for classes that execute business logic. @repositoryUsed for data layer classes. Mainly used for classes that access db. @componentIn addition to the above, it is used for di target classes.



Spring main points


RESTful Web Service created with Spring Boot

https://www.slideshare.net/WataruOhno/spring-fest-2018-spring-bootrestful-web-service https://terasolunaorg.github.io/guideline/5.0.1.RELEASE/ja/ArchitectureInDetail/REST.html

Recommended Posts

Spring boot memo writing (1)
Spring boot memo writing (2)
Spring boot controller method memo
◆ Spring Boot + gradle environment construction memo
A memo that touched Spring Boot
Spring retrospective memo
Challenge Spring Boot
Spring Boot Form
Spring Boot Memorandum
gae + spring boot
Spring Boot environment construction memo on mac
Spring Boot + Thymeleaf BootStrap installation method memo
JJUG CCC Spring 2018 memo
SPRING BOOT learning record 01
Spring Boot + Heroku Postgres
Spring Shell usage memo
First Spring Boot (DI)
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
Learning Spring Boot [Beginning]
Spring Boot 2.2 Document Summary
Annotation notes when writing tests for Spring Boot
[Spring Boot] DataSourceProperties $ DataSourceBeanCreationException
Spring Boot 2.3 Application Availability
Spring boot tutorials Topics
Download with Spring Boot
Spring Security usage memo: Cooperation with Spring MVC and Boot
[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
Implement GraphQL with Spring Boot
Spring Security usage memo CSRF
Spring Framework self-study memo series_1
Spring Boot tutorial task schedule
Spring 5 & Spring Boot 2 Hands-on preparation procedure
Get started with Spring boot
Spring Security usage memo Run-As
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)
Introduction to Spring Boot ① ~ DI ~
Spring Security usage memo Remember-Me
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