Here's a summary of my personal best practices as of June 2018 regarding the combination of tools when implementing REST APIs in Spring Boot.
→ As an IDE, it is used in the official Android development environment, and IntelliJ IDEA is likely to become widespread in the future, but Ultimate Edition is required to use the Spring development support function. Eclipse is a good choice for projects that aren't as good as buying a license.
→ Gradle, which allows you to write processing flexibly with Groovy, is likely to become mainstream in the future. However, Maven is sufficient if it is only used for dependency resolution and build.
→ JAX-RS is a Java standard specification, and the implementation libraries that can be used at the operation level have been enhanced, so it is better to use spring-boot-starter-jersey.
→ It is easy to set Spring AOP with AspectJ annotation, and the setting can be summarized in the code. However, if you want to set the aspect to an instance that is not managed by Spring, or if you want to set it at a timing other than method execution, you need to use AspectJ.
→ spring-boot-starter-data-jpa is convenient because simple database operations can be described without SQL.
In addition, it is necessary to install the corresponding connector to connect with each DB. (For example, in the case of MySQL, install mysql-connector-java.)
→ It is better to use Hikari CP, which has excellent performance and is recommended by Spring Boot.
→ When using transactions for a single transaction target resource (DB, MQ, etc.), the transaction management function of Spring Framework is sufficient. According to the Spring reference, if you want to use transactions across multiple resources, you should either combine Spring with the JTA function of the application server, or use a transaction library such as Atomikos.
→ AutoValue is strictly a library for creating Immutable Value Class, but in Lombok, you can use it just by adding an accessor method to a general class, and it can be used in many ways. However, if you want to extend the code generation function, it is better to implement the Extension of AutoValue. (Lombok supports Extension Method on a trial basis, but it is unclear if it will be included in the official version.)
You can easily read the configuration file by using spring-boot-configuration-processor. There are three ways to read the configuration file.
@Value
to set the member variable to the value corresponding to the key in the configuration file.@ConfigurationProperties
to set the contents of the configuration file for the bean→ Since settings often have a hierarchical structure, it is easy to use @ConfigurationProperties
.
→ SLF4J + Logback is likely to become the mainstream in the future. Even if you are using other logging systems, you can aggregate them into SLF4J by the method introduced in Bridging legacy APIs.
If there is no problem, it is better to use spring-boot-test. AssertJ (assertion), Hamcrest (match operation), [Mockito](http: / The library required for testing, such as /mockito.org/) (mock), is complete.
Recommended Posts