- 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.
- Puppet 4 Essentials(Second Edition)
- Python for Secret Agents:Volume II
- Unity 2020 Mobile Game Development
- Oracle 12c中文版數據庫管理、應用與開發實踐教程 (清華電腦學堂)
- 新編Premiere Pro CC從入門到精通
- Spring實戰(第5版)
- 軟件項目管理實用教程
- C語言程序設計同步訓練與上機指導(第三版)
- 持續輕量級Java EE開發:編寫可測試的代碼
- C++20高級編程
- Unity 3D腳本編程:使用C#語言開發跨平臺游戲
- 軟件項目管理實用教程
- Odoo 10 Implementation Cookbook
- Continuous Delivery and DevOps:A Quickstart Guide Second Edition
- MySQL數據庫應用實戰教程(慕課版)