Add these using Spring Initializr or by manually adding them to your pom.xml
. They cover projects using test-driven-development, microservices, containerization, and more. Be sure to use the most up-to-date versions!
Allows an application to accept HTTP requests. Build web, including RESTful, applications using Spring MVC. Uses Apache Tomcat as the default embedded container.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
NOT from Spring Initializr.
Allows us to use JUnit 4 for testing.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
Allows us to set validation constraints (ISR303 - like @NotEmpty, @Min
) on our model fields. Enables @Valid to enforce/run constraints.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
NOT from Spring Initializr.
Allows us to automatically generate Swagger/OpenAPI documentation for our API.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.4</version>
</dependency>
Enables the use of Spring Data JPA in applications, including the JPARepository class and automatic creation of tables and columns in the database.
In order to use a JPARepository<type, typeOfPrimaryKey>
interface, use the @Repository
annotation so that the application will make an instance to use.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Enables an application to connect to MySQL database(s). We configured our database properties in application.properties
.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
This is required in order to make an application function as a configuration server.
- Part of Spring Cloud Config.
- Also, annotate the main class with
@EnableConfigServer
. - Set
server.port
in properties. - Set location of GitHub repository that contains configurationn files in properties.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
This is required for an application to request its configuration from a config server.
- Part of Spring Cloud Config.
- Set
spring.application.name
in properties. - Include the location of the config server to properties with
spring.config.import=optional.configserver:http://localhost:9999/
. This will connect to a config server running locally on port 9999.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
Supports built-in (or custom) endpoints that let you monitor and manage your application. We used this to allow our application to re-read its configuration without needing to restart the application.
- Mark a class with
@RefreshScope
. - Read values from configuration into instance variables using the
@Value
annotation. - Add the following to properties
management.endpoints.web.exposure.includes=*
.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Allows an application to be a Eureka Server/Service Registry.
- Part of Spring Cloud Config.
- Mark main class with
@EnableEurekaServer
. - Check Eureka dashboard at
http://localhost:8761
if your server is running on port 8761. - Set port and disable High Availability in properties file as follows:
server.port=8761
eureka.instance.hostname=localhost
# Shut off the client functionality of the Eureka server (used for HA)
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
Allows an application to be a Eureka client. A Eureka client registers with a Eureka server and uses it to discover other services.
- Part of Spring Cloud Config.
- Must set
spring.application.name
in properties.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
NOT from Spring Initializr.
- Part of Spring Cloud Config.
- Important: Annotate the main class with
@EnableFeignClient(name=<service_name>)
. For example,@FeignClient(name="<service_name>")
. The name is looked up using the Service Registry. Therefore, this dependency is generally used with the Eureka Client dependency.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<version>1.4.7.RELEASE</version>
</dependency>
NOT from Spring Initializr.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
</dependency>
- Part of Spring Cloud Config.
- Important: Add
@EnableCaching
to main class. - Add
@CacheConfig(nameName={<name>})
to controller that does the caching. For example, for a cache namedrsvps
:@CacheConfig(cacheName={"rsvps"})
.