Skip to content

Instantly share code, notes, and snippets.

@andycwilliams
Last active November 14, 2023 08:51
Show Gist options
  • Save andycwilliams/3eb923ef63ad9029021458d7142ead43 to your computer and use it in GitHub Desktop.
Save andycwilliams/3eb923ef63ad9029021458d7142ead43 to your computer and use it in GitHub Desktop.
Breakdown of common Maven dependencies.

Maven Dependencies:

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!

Spring Web [ WEB ]:

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>

JUnit:

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>

Validation [ I/O ]:

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>

Springdoc:

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>

Spring Data JPA [ SQL ]:

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>

MySQL Driver [ SQL ]:

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>

Config Server [ SPRING CLOUD CONFIG ]:

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>

Config Client [ SPRING CLOUD CONFIG ]:

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>

Spring Boot Actuator [ OPS ]

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>

Eureka Server [ SPRING CLOUD DISCOVERY ]

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>

Eureka Discovery Client [ SPRING CLOUD DISCOVERY ]

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>

Feign Client

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>

Queues:

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>

Spring Cache Abstration [ I/O ]

  • 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 named rsvps: @CacheConfig(cacheName={"rsvps"}).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment