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.
Red Hat (development environment is Cent) 7 series Java8 SpringBoot2.1.6 MySQL8 series STS
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
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 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
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
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:
Memo after the first Spring project-Database- Memo after the first Spring project-MVC-
Recommended Posts