本文主要是介绍intelij idea创建spring boot聚合工程,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、快速创建spring boot工程(父工程)。
(1.1) File -> New - > Project -> Spring Assistant-> 点击Next 。如图选择default,然后点击next。
(1.2)填写项目相关信息,如图:
(1.3)下一步,选择core下devtools(热部署),如图:
(1.4)选择文件位置:
(1.5)创建完之后删除src目录,并修改pom.xml,如下:
<?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.tianshuhao</groupId><artifactId>tianshuhao-parent</artifactId><version>0.0.1-SNAPSHOT</version><packaging>pom</packaging><name>tianshuhao-parent</name><description>tianshuhao-parent project for Spring Boot</description><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.6.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><fastjson.version>1.2.51</fastjson.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>2.0.6.RELEASE</version><type>pom</type><scope>import</scope></dependency><!--热部署--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><build><!-- 产生构件的文件名,默认${artifactId}-${version} --><finalName>tianshuhao-parent</finalName><pluginManagement><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></pluginManagement><plugins><!-- 跳过测试 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><configuration><skip>true</skip></configuration></plugin></plugins></build>
</project>
2、创建核心模块core,entity,dao,service,web。
(2.1)项目上右键单击new-----Module:
(2.2)选择core下的lombok(简化代码,可省略getter/setter/toString等方法),选择路径,如图:
(2.3)模仿core创建其他模块,entity,dao,service和web(其中web打包方式选择war,最后一步项目依赖添加web),如图:
(2.4)创建完后目录结构如图:
(2.5)删除各个模块包下的无用类,只保留到包即可(web模块除外)。
3、父工程的pom.xml文件添加<modules>标签,如图:
4、子模块添加父工程,entity,dao,service,web模块依赖core模块,dao添加entity模块......最后:
(4.1)core模块的pom.xml:
<?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"><parent><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-parent</artifactId><version>0.0.1-SNAPSHOT</version><relativePath>../pom.xml</relativePath></parent><modelVersion>4.0.0</modelVersion><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-core</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>tianshuhao-core</name><description>tianshuhao-core project for tianshuhao</description><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><!-- lombok --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><!--fastjson--><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>${fastjson.version}</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
</project>
(4.2)entity模块的pom.xml:
<?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"><parent><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-parent</artifactId><version>0.0.1-SNAPSHOT</version><relativePath>../pom.xml</relativePath></parent><modelVersion>4.0.0</modelVersion><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-entity</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>tianshuhao-entity</name><description>tianshuhao-entity project for tianshuhao</description><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-core</artifactId><version>0.0.1-SNAPSHOT</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
</project>
(4.3)dao模块的pom.xml:
<?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"><parent><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-parent</artifactId><version>0.0.1-SNAPSHOT</version><relativePath>../pom.xml</relativePath></parent><modelVersion>4.0.0</modelVersion><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-dao</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>tianshuhao-dao</name><description>tianshuhao-dao project for tianshuhao</description><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-core</artifactId><version>0.0.1-SNAPSHOT</version></dependency><dependency><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-entity</artifactId><version>0.0.1-SNAPSHOT</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
</project>
(4.4)service模块的pom.xml:
<?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"><parent><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-parent</artifactId><version>0.0.1-SNAPSHOT</version><relativePath>../pom.xml</relativePath></parent><modelVersion>4.0.0</modelVersion><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-service</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>tianshuhao-service</name><description>tianshuhao-service project for tianshuhao</description><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-core</artifactId><version>0.0.1-SNAPSHOT</version></dependency><dependency><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-entity</artifactId><version>0.0.1-SNAPSHOT</version></dependency><dependency><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-dao</artifactId><version>0.0.1-SNAPSHOT</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-cache</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
</project>
(4.5)web模块的pom.xml:
<?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"><parent><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-parent</artifactId><version>0.0.1-SNAPSHOT</version><relativePath>../pom.xml</relativePath></parent><modelVersion>4.0.0</modelVersion><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-web</artifactId><version>0.0.1-SNAPSHOT</version><packaging>war</packaging><name>tianshuhao-web</name><description>tianshuhao-web project for tianshuhao</description><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-core</artifactId><version>0.0.1-SNAPSHOT</version></dependency><dependency><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-entity</artifactId><version>0.0.1-SNAPSHOT</version></dependency><dependency><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-dao</artifactId><version>0.0.1-SNAPSHOT</version></dependency><dependency><groupId>com.tianshuhao</groupId><artifactId>tianshuhao-service</artifactId><version>0.0.1-SNAPSHOT</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><!--排除内置的tomcat--><!--<exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId></exclusion></exclusions>--></dependency><!--<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId><scope>provided</scope></dependency>--></dependencies><build><!-- 产生构件的文件名,默认${artifactId}-${version} --><finalName>tianshuhao-web</finalName></build>
</project>
5、项目打包,调出maven projects窗口,如图目录运行run maven build:
6、控制台显示build success表示打包成功,如图:
7、修改web模块的application.proterties为application.yml,并添加一下内容:
8、同级目录(resources)下添加文件application-dev.properties,内容为空即可。
9、web子模块的Application启动类:
10、运行main方法,访问地址:http://localhost:8080/tianshuhao-web/test
这篇关于intelij idea创建spring boot聚合工程的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!