對於Maven管理的項目,還是習慣於多模塊。將項目結構做下調整。
1。修改springboot項目的pom文件。
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 6 <groupId>com.taynio.demo</groupId> 7 <artifactId>springboot</artifactId> 8 <version>0.0.1-SNAPSHOT</version> 9 <packaging>pom</packaging> 10 11 <name>springboot</name> 12 <description>Demo project for Spring Boot</description> 13 14 <parent> 15 <groupId>org.springframework.boot</groupId> 16 <artifactId>spring-boot-starter-parent</artifactId> 17 <version>1.3.3.RELEASE</version> 18 <relativePath/> <!-- lookup parent from repository --> 19 </parent> 20 21 <properties> 22 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 23 <java.version>1.8</java.version> 24 </properties> 25 26 <build> 27 <plugins> 28 <plugin> 29 <groupId>org.springframework.boot</groupId> 30 <artifactId>spring-boot-maven-plugin</artifactId> 31 </plugin> 32 </plugins> 33 </build> 34 35 </project>
將springboot項目作為頂級項目。在此基礎上,新建Maven模塊項目web-rest模塊。
IntelliJ IDEA會自動給我們springboot 項目的pom.xml文件添加模塊聲明。
<modules>
<module>web-rest</module>
</modules>
2。修改web-rest項目的pom.xml文件。
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 7 <parent> 8 <artifactId>springboot</artifactId> 9 <groupId>com.taynio.demo</groupId> 10 <version>0.0.1-SNAPSHOT</version> 11 </parent> 12 <artifactId>web-rest</artifactId> 13 <packaging>jar</packaging> 14 15 <dependencies> 16 <dependency> 17 <groupId>org.springframework.boot</groupId> 18 <artifactId>spring-boot-starter-web</artifactId> 19 </dependency> 20 21 <dependency> 22 <groupId>org.springframework.boot</groupId> 23 <artifactId>spring-boot-starter-test</artifactId> 24 <scope>test</scope> 25 </dependency> 26 </dependencies> 27 28 <build> 29 <plugins> 30 <plugin> 31 <groupId>org.springframework.boot</groupId> 32 <artifactId>spring-boot-maven-plugin</artifactId> 33 </plugin> 34 </plugins> 35 </build> 36 37 </project>
3。建立SpringBoot的啟動程序。
新建Java類:com.taynio.demo.springboot.SpringbootWebRestApplication:
1 package com.taynio.demo.springboot; 2 3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5 6 /** 7 * Created by Zhantao on 2016/3/24. 8 * Date:2016/3/24 15:28 9 * Email: 10 */ 11 @SpringBootApplication 12 public class SpringbootWebRestApplication { 13 14 public static void main(String[] args) { 15 SpringApplication.run(SpringbootWebRestApplication.class, args); 16 } 17 18 }
運行。web-rest項目模塊創建成功。