Difference between revisions of "Spring 5 training (Spring guru) - personal notes"

Line 58: Line 58:
  
 
=IntelliJ configuration=
 
=IntelliJ configuration=
 +
 +
==Plugins==
  
 
Useful plugings:
 
Useful plugings:
Line 63: Line 65:
 
** .ignore
 
** .ignore
 
** Ideolog
 
** Ideolog
 +
** GenerateSerialVersion
  
 
Enable toolbars! View > Toolbar
 
Enable toolbars! View > Toolbar
 +
 +
 +
==Import optimization==
 +
 +
see https://stackoverflow.com/questions/11704327/how-to-optimize-imports-automatically-after-each-save-in-intellij-idea
 +
 +
 +
IntelliJ IDEA offers 2 options:
 +
* '''Settings''' | Editor | General | Auto Import > Optimize imports on the fly
 +
* '''Commit Project dialog''' > Optimize imports option

Revision as of 15:43, 9 March 2018


I recently (2018) subscribe to an online training related to Spring 5 on Udemy. This page is a sum-up of my personal notes related to Spring 5.


Links

  • Spring initializr - to generate a quick start project based on the libraries you choose


Very simple web-application

  • Go to Spring initializr
  • Select
    • web > web
    • SQL > JPA
    • SQL > H2
    • Templates > Thymeleaf
    • Ops > actuator


H2 hint

When using H2 on a web application, don't forget to enable the console! Edit application.properties as follow:

spring.h2.console.enabled=true
# replace "spring5webapp" by your own application
spring.datasource.url=jdbc:h2:mem:spring5webapp;DB_CLOSE_ON_EXIT=FALSE

Then you can reach the console at http://localhost:8080/h2-console


Hibernate

General notes

Hibernate recommends to implement hashCode() and equals() on all JPA entities. They also recommend to use a particular Business ID when possible, if not then use the ID. Only the key fields should be in these methods.


How to run project

Spring boot provides some out-of-the-box tools.

To run the application:

# Using the maven installation (outside the project)
mvn spring-boot:run

# Using the embedded tool
./mvnw spring-boot:run


IntelliJ configuration

Plugins

Useful plugings:

  • File > Settings > Plugins > Browse repositories
    • .ignore
    • Ideolog
    • GenerateSerialVersion

Enable toolbars! View > Toolbar


Import optimization

see https://stackoverflow.com/questions/11704327/how-to-optimize-imports-automatically-after-each-save-in-intellij-idea


IntelliJ IDEA offers 2 options:

  • Settings | Editor | General | Auto Import > Optimize imports on the fly
  • Commit Project dialog > Optimize imports option