[JAVA] Spring Boot for annotation learning

It is for my own learning.

I started using Spring in my current project.

I don't understand the annotations that are characteristic of Java and Spring => Efficient implementation is not possible. Spring has not been used effectively.

The one in App.java @SpringBootApplication The class with this annotation indicates that it is a Spring Boot application class. There is a run method that boots Spring. It is used when you want to add various setting information at the time of execution.

@EnableScheduling Enable the schedule function. -> Allow use of @Scheduled

@Scheduled You can specify the execution time of the method. Periodic execution can be performed by taking the following arguments to the annotation. You can also use cron. Details ⇒ https://qiita.com/rubytomato@github/items/4f0c64eb9a24eaceaa6e

Lombok (the one that automatically creates getters and setters) related annotations There are three types. @NoArgsConstructor,@RequiredArgsConstructor, @AllArgsConstructor

These three are annotations that automatically generate a constructor when creating getters / setters with lombok.

@ </ span> NoArgsConstructor Generates a default constructor with no arguments. @ </ span> RequiredArgsConstructor creates a constructor with arguments to set values in fields with final. @ </ span> AllArgsConstructor Generates a constructor that takes initialization values for all fields as arguments

Behavior of RequiredArgsConstructor

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class Employee {

    private final int id;

    private String name;
}

Generated code

public class Employee {
    private final int id;
    private String name;

    public Employee(final int id) {
        this.id = id;
    }
}
//Names without the final qualifier are not included in the constructor.

In ongoing PJ It is used in the form of @ </ span> RequiredArgsConstructor (onConstructor = @ </ span> __ ( @ </ span> Autowired)).

onConstructor = @ </ span> __ ( @ </ span> Autowired)) I wondered what (?), So I looked it up. According to the official Lambok documentation, it's placed to annotate the generated constructor (!?) https://projectlombok.org/features/constructor About onX-> OnConstructor, it was written as follows. "we heard you like annotations, so we put annotations in your annotations so you can annotate while you're annotating." "We heard that you like annotations, so I put them in your annotations, so you can annotate while you're annotating."

Recommended Posts

Spring Boot for annotation learning
SPRING BOOT learning record 01
SPRING BOOT learning record 02
Spring Boot learning procedure
Learning Spring Boot [Beginning]
Annotation notes when writing tests for Spring Boot
Spring Boot for the first time
Frequent annotations for Spring Boot tests
For JAVA learning (2018-03-16-01)
Challenge Spring Boot
WebMvcConfigurer Memorandum of Understanding for Spring Boot 2.0 (Spring 5)
Spring Boot Form
Spring Boot Memorandum
gae + spring boot
Spring Boot + Heroku Postgres
Spring boot memo writing (1)
First Spring Boot (DI)
Spring Boot2 cheat sheet
Spring Boot exception handling
Spring Boot Servlet mapping
Spring boot development-development environment-
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
Ruby Learning # 23 For Loops
Download with Spring Boot
Plans to support JDK 11 for Eclipse and Spring Boot
Settings for connecting to MySQL with Spring Boot + Spring JDBC
Switch environment with Spring Boot application.properties and @Profile annotation
How to write a unit test for Spring Boot 2
[Spring Boot] How to create a project (for beginners)
Customizer for Platform Transaction Manager added from Spring Boot 1.5
Create a web app that is just right for learning [Spring Boot + Thymeleaf + PostgreSQL]
Steps required to issue an asynchronous event for Spring Boot
Set context-param in Spring Boot
Hello World with Spring Boot
Spring Boot on Microsoft Azure
Change the injection target for each environment with Spring Boot 2
Implement GraphQL with Spring Boot
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
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
Introductory hands-on for beginners of Spring 5 & Spring Boot 2 has been released
Set cookies with Spring Boot
[Spring Boot] Easy paging recipe