- Docker and Kubernetes for Java Developers
- Jaroslaw Krochmalski
- 289字
- 2021-07-02 18:44:58
Maven build file
As you will see, the parent project for our own service is spring-boot-starter-parent. Spring this is the parent project providing dependency and plugin management for Spring Boot-based applications. This gives us a lot of features to start with. We also include two starters:
- spring-boot-starter-web: This is because we are going to create our request mappings (similar to @GET or @POST mappings with the @Path annotation we did previously using JEE7 JAX-RS
- spring-boot-starter-data-jpa: Because we are going to save our books in the in-memory H2 database
Starters are simplified dependency descriptors customized for different purposes. For example, spring-boot-starter-web is the starter for building web and RESTful, applications using Spring MVC. It uses Tomcat as the default embedded container. We also include the Spring Boot Maven plugin, which allows us to run the applications in place without building a JAR or a WAR, or preparing a JAR or WAR file for future deployment. Our complete pom.xml should look the same as this:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>pl.finsys</groupId> <artifactId>rest-example</artifactId> <version>0.1.0</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-
parent</artifactId> <version>1.5.2.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-
web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-
jpa</artifactId> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> </dependency> <dependency> <groupId>org.hsqldb</groupId> <artifactId>hsqldb</artifactId> <scope>runtime</scope> </dependency> <!--test dependencies--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>com.jayway.jsonpath</groupId> <artifactId>json-path</artifactId> <scope>test</scope> </dependency> </dependencies> <properties> <java.version>1.8</java.version> </properties> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <repositories> <repository> <id>spring-releases</id> <url>https://repo.spring.io/libs-release</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-releases</id> <url>https://repo.spring.io/libs-release</url> </pluginRepository> </pluginRepositories> </project>
First, in the pom.xml file, we define the parent Maven artifact. As our application is the Spring Boot application, we inherit our pom.xml from the spring-boot-starter-parent artifact. This gives us all the Spring Boot goodies out of the box, such as the startup mechanism, dependency injection, and so on. By adding spring-boot-starter-data-jpa as a dependency, we will be able to use all the database-related features, such as JDBC transaction management, JPA annotations for the entity classes, and so on. Having the pom.xml ready, let's continue and define the entry point for our microservice.
- MySQL 8從入門到精通(視頻教學版)
- 算法訓練營:入門篇(全彩版)
- Learning C++ Functional Programming
- PyTorch Artificial Intelligence Fundamentals
- Quarkus實踐指南:構建新一代的Kubernetes原生Java微服務
- Python算法從菜鳥到達人
- HTML5開發精要與實例詳解
- Visual Basic程序設計習題與上機實踐
- Troubleshooting Citrix XenApp?
- Mastering Adobe Captivate 7
- Learning Python Data Visualization
- 高效使用Greenplum:入門、進階與數據中臺
- Android編程權威指南(第4版)
- XML程序設計(第二版)
- Scratch少兒編程高手的7個好習慣