Memo after the first Spring project-What is Spring-

Introduction

Only the basic knowledge of pure Java and DB The Spring project from the start has settled down after the turbulence, so please give us your impressions and memorandum. : speech_balloon: The content of the article is more than a tutorial and less than a practice.

Development environment

Red Hat (development environment is Cent) 7 series Java8 SpringBoot2.1.6 MySQL8 series STS

About Spring Framework

With a 10-year framework, you can do most of the things, that is, messed up. When you get information, check the freshness, whether it's a book or online. Especially regarding settings, it is already free from XML hell and can often be described in annotations and application.properties. https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html

About application.properties

It seems that application.yml, which I learned later, is easier to read. What can be set is ↓. It's a good idea to take a quick look at it in your spare time. https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html

application.properties can be switched depending on the environment. --Spring.profiles.active when running from the command line https://qiita.com/NagaokaKenichi/items/fd9b5e698776fe9b9cc4 When running from STS propatiese.PNG It's deep, so if you use it with a twist, you'll be addicted to it. Let's keep it simple. : unamused: https://blog.tagbangers.co.jp/ja/2019/07/12/how-spring-deals-with-properties

WEB system configuration created by Spring

MVC offers DI and AOP design. It is useful when designing or searching for bugs if you can imagine the configuration diagram in your head. Listeners, custom validation implementations, test code environments, and so on. https://qiita.com/kazuki43zoo/items/757b557c05f548c6c5db

About DI

After all, understanding that "controllers and DB-related classes are subject to DI". I used to do @Autowired, but it doesn't seem to be good. It seems that the mainstream now is to use constructor injection. https://qiita.com/jackazu/items/aead50c699fefe56c120 What you have to be aware of is that if you add @Controller, Spring will judge it as a DI target and instantiate it without permission, so do not usenew HogeController (). Because it will be null.

The instance targeted for DI is a singleton. It seems that it can be changed depending on the setting, but if you think that you have to change it, you should doubt the design. When I kept the user information in the member variable of the controller **, it was rewritten more and more by another user **. : laughing:

Other notes

Memo after the first Spring project-Database- Memo after the first Spring project-MVC-

Recommended Posts

Memo after the first Spring project-What is Spring-
Memo after the first Spring project-MVC-
Memo after the first Spring project-Database-
This is the first post.
Spring Boot for the first time
Spring AOP for the first time
Spring retrospective memo
The official name of Spring MVC is Spring Web MVC
Learning memo when learning Java for the first time (personal learning memo)
Books read after the first year engineer joined the company
JJUG CCC Spring 2018 memo
Spring Shell usage memo
Spring boot memo writing (1)
First Spring Boot (DI)
What is Spring Tools 4
Spring boot memo writing (2)
The first WEB application with Spring Boot-Making a Pomodoro timer-