Java Spring Boot
Read more at Learn the path
Definitions
- Group ID: Identifies the organization. Example: com.google
- Artifact ID: Determines the name of the application.
Compile and Run
# Auto detect changes
gradlew -t :bootJar
# Compile and run
gradlew bootRun
Packages
- Spring Boot DevTools: Provides fast application restarts, LiveReload, and configurations for enhanced development experience.
Three layers architecture
This architecture considers:
- Presentation layer (model + view + controller)
- Business logic (service): it has all the business operations (computation and decision making processes)
- Data access layer (repository): it has all the CRUD operations.

Annotations
@Componentannotation is too generic. Use@Servicefor business logic layer and@Repositoryfor the data access layer instead. They all turn aclassinto aBean.@Controlleralso derives from@Component.@Configurationmarks a class as a source ofBeansdefinitions.@Autowiredwires the class into theBeanthat needs it.@RestController=@Controller+@ResponseBody.@ResponseBodyconverts the output toJSON.
Best practices
Dependency injection
- Never ever create an object inside of a class that depends on it. This is called tight coupling and makes unite testing impossible. Instead, use dependency injection.
