创建springboot的Maven模块。
对于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 @SpringBootApplication12 public class SpringbootWebRestApplication {13 14 public static void main(String[] args) {15 SpringApplication.run(SpringbootWebRestApplication.class, args);16 }17 18 }
运行。web-rest项目模块创建成功。