Business efficiency
** 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.
`@ 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.
@SpringBootApplication
/* demo.service and demo.Of the domain and below@Annotation for component and DI registration
Classes granted/Register the method in the DI container as a bean.*/
@ComponentScan(
scopedProxy = ScopedProxyMode.TARGET_CLASS,
basePackages = {"demo.service","demo.domain"}
)
public class SBDataBaseDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SBDataBaseDemoApplication.class, args);
}
}
@controller
Used for controller layer classes.
@restcontroller
Used for webapi controller layer classes.@controller
When@responsebody
It is a combination of.
@service
Used for service layer classes. Mainly used for classes that execute business logic.
@repository
Used for data layer classes. Mainly used for classes that access db.
@component
In addition to the above, it is used for di target classes.
Spring main points
https://atuweb.net/201509_spring_framework_good_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