- Mastering Microservices with Java 9(Second Edition)
- Sourabh Sharma
- 339字
- 2021-07-02 21:54:44
Adding Spring Boot to our main project
We will use the Java 9 to develop microservices. Therefore, we'll use the latest Spring Framework and Spring Boot project. At the time of writing, Spring Boot 2.0.0 build snapshot release version was available.
You can use the latest released version. Spring Boot 2.0.0 build snapshot uses Spring 5 (5.0.0 build snapshot release).
Let's take a look at the following steps and learn about adding Spring Boot to our main project:
- Open the pom.xml file (available under 6392_chapter2 | Project Files) to add Spring Boot to your sample project:
<?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>com.packtpub.mmj</groupId> <artifactId>6392_chapter2</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <modules> <module>lib</module> <module>rest</module> </modules> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <spring-boot-version>2.0.0.BUILD-SNAPSHOT</spring-boot-version> <spring-version>5.0.0.BUILD-SNAPSHOT</spring-version> <maven.compiler.source>9</maven.compiler.source> <maven.compiler.target>9</maven.compiler.target> <start-class>com.packtpub.mmj.rest.RestSampleApp</start-class> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.0.BUILD-SNAPSHOT</version> </parent> <dependencyManagement> <dependencies> <dependency> <groupId>com.packtpub.mmj</groupId> <artifactId>rest</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>com.packtpub.mmj</groupId> <artifactId>lib</artifactId> <version>${project.version}</version> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.0.0.BUILD-SNAPSHOT</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> <configuration> <classifier>exec</classifier> <mainClass>${start-class}</mainClass> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>1.9</source> <target>1.9</target> <showDeprecation>true</showDeprecation> <showWarnings>true</showWarnings> </configuration> </plugin> </plugins> </build> <repositories> <repository> <id>spring-snapshots</id> <name>Spring Snapshots</name> <url>https://repo.spring.io/snapshot</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-snapshots</id> <name>Spring Snapshots</name> <url>https://repo.spring.io/snapshot</url> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> <pluginRepository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> </project>
You can observe that we have defined our two modules lib and rest in parent project pom.xml.
- If you are adding these dependencies for the first time, you need to download the dependencies by right-clicking on the Dependencies folder under the 6392_chapter2 project in the Projects pane, as shown in the following screenshot:

Download Maven Dependencies in NetBeans
- Similarly, to resolve the project problems, right-click on the NetBeans project 6392_chapter2 and opt for the Resolve Project Problems.... It will open the dialog shown as follows. Click on the Resolve... button to resolve the issues:

Resolve project problems dialog
- If you are using Maven behind the proxy, then update the proxies in settings.xml in Maven home directory. If you are using the Maven bundled with NetBeans then use <NetBeans Installation Directory>\java\maven\conf\settings.xml. You may need to restart the NetBeans IDE.
The preceding steps will download all the required dependencies from a remote Maven repository if the declared dependencies and transitive dependencies are not available in a local Maven repository. If you are downloading the dependencies for the first time, then it may take a bit of time, depending on your internet speed.
- Java 開發(fā)從入門到精通(第2版)
- R語言經(jīng)典實(shí)例(原書第2版)
- JavaScript+jQuery開發(fā)實(shí)戰(zhàn)
- 我的第一本算法書
- 數(shù)據(jù)結(jié)構(gòu)(Python語言描述)(第2版)
- Processing互動(dòng)編程藝術(shù)
- Expert Data Visualization
- SQL Server 2016數(shù)據(jù)庫應(yīng)用與開發(fā)
- .NET 3.5編程
- Oracle 18c 必須掌握的新特性:管理與實(shí)戰(zhàn)
- C++面向?qū)ο蟪绦蛟O(shè)計(jì)習(xí)題解答與上機(jī)指導(dǎo)(第三版)
- HTML5從入門到精通 (第2版)
- 蘋果的產(chǎn)品設(shè)計(jì)之道:創(chuàng)建優(yōu)秀產(chǎn)品、服務(wù)和用戶體驗(yàn)的七個(gè)原則
- Building Serverless Web Applications
- OpenCV 3 Blueprints