IDEA创建springboot聚合项目

使用idea创建springboot很简单,但是基于springboot的聚合工程很多小伙伴都是不会的,在这里我分享一下我自己搭建springboot聚合工程的经验

一.创建聚合父工程

1.首先使用 Spring Initializr 来快速创建好一个Maven工程。然后删除无关的文件,保留pom.xml 文件 ,将打包方式改为pom如下。

IDEA创建springboot聚合项目_第1张图片

2.创建demo项目的子模块,在项目上右键单击,选择:new -> Module 分别为springboot-web,

springboot-service,springboot-dao,springboot-entity   4个子项目   创建完成后目录如下

IDEA创建springboot聚合项目_第2张图片

3.删除子模块中 src/main/java、src/main/java下的所有文件,只保留web子模块的SpringBoot的Application主启动类

4.更改父工程的pom.xml   文件为如下  注意标签是否指定了子模块



	4.0.0

	com.example
	demo
	0.0.1-SNAPSHOT
	pom

	demo
	Demo project for Spring Boot

    
        springboot-web
        springboot-service
        springboot-dao
        springboot-entity
    

    
		org.springframework.boot
		spring-boot-starter-parent
		2.0.4.RELEASE
		 
	

	
		UTF-8
		UTF-8
		1.8
	

	
		
			org.springframework.boot
			spring-boot-starter
		

		
			org.springframework.boot
			spring-boot-starter-test
			test
		
	

	
	
		
			
				org.apache.maven.plugins
				maven-compiler-plugin
				3.1
				
					${java.version}
					${java.version}
				
			

			
				org.apache.maven.plugins
				maven-surefire-plugin
				2.19.1
				
					true    
				
			
		
	



5.web子模块pom.xml(依赖service、dao、entity子模块)



	4.0.0

	com.example
	springboot-web
	0.0.1-SNAPSHOT
	jar

	springboot-web
	Demo project for Spring Boot

	
		org.springframework.boot
		spring-boot-starter-parent
		2.0.4.RELEASE
		 
	

	
		UTF-8
		UTF-8
		1.8
	

	
		
			com.example
			springboot-service
			0.0.1-SNAPSHOT
		
		
			com.example
			springboot-dao
			0.0.1-SNAPSHOT
		
		
			com.example
			springboot-entity
			0.0.1-SNAPSHOT
		

		
			org.springframework.boot
			spring-boot-starter
		

		
			org.springframework.boot
			spring-boot-starter-test
			test
		
	




6.service子模块pom.xml(依赖 dao 、entity子模块)



	4.0.0

	com.example
	springboot-service
	0.0.1-SNAPSHOT
	jar

	springboot-service
	Demo project for Spring Boot

	
		com.example
		demo
		0.0.1-SNAPSHOT
		../pom.xml
	

	
		UTF-8
		UTF-8
		1.8
	

	
		
			com.example
			springboot-entity
			0.0.1-SNAPSHOT
		
		
			com.example
			springboot-dao
			0.0.1-SNAPSHOT
		
		
			org.springframework.boot
			spring-boot-starter
		

		
			org.springframework.boot
			spring-boot-starter-test
			test
		
	





7.dao子模块pom.xml (依赖entity子模块)



	4.0.0

	com.example
	springboot-dao
	0.0.1-SNAPSHOT
	jar

	springboot-dao
	Demo project for Spring Boot

	
		com.example
		demo
		0.0.1-SNAPSHOT
		../pom.xml
	

	
		UTF-8
		UTF-8
		1.8
	

	
		
			com.example
			springboot-entity
			0.0.1-SNAPSHOT
		

		
			org.springframework.boot
			spring-boot-starter
		

		
			org.springframework.boot
			spring-boot-starter-test
			test
		
	




8.entity子模块



	4.0.0

	com.example
	springboot-entity
	0.0.1-SNAPSHOT
	jar

	springboot-entity
	Demo project for Spring Boot

	
		com.example
		demo
		0.0.1-SNAPSHOT
		../pom.xml
	

	
		UTF-8
		UTF-8
		1.8
	

	
		
			org.springframework.boot
			spring-boot-starter
		

		
			org.springframework.boot
			spring-boot-starter-test
			test
		
	





9.注意 打包方式已经更改 所以 

 

 

IDEA创建springboot聚合项目_第3张图片

图中红色框圈中的部分一定要删除 或者复制我上面的pom 

10.打包方式如下图

 

IDEA创建springboot聚合项目_第4张图片

打包成功如下图

IDEA创建springboot聚合项目_第5张图片

11.web子模块的Application启动类:

package com.example.springbootweb;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@EnableAutoConfiguration
@SpringBootApplication
@RestController
public class SpringbootWebApplication {

	public static void main(String[] args) {

		SpringApplication.run(SpringbootWebApplication.class, args);
	}
	@RequestMapping(value = "/test",method = RequestMethod.GET)
	public String test(){
		return "test success";
	}

}

12.执行main方法启动项目,访问localhost:8080/test,出现如下页面表示项目搭建成功

IDEA创建springboot聚合项目_第6张图片

至此springboot聚合项目搭建成功 ,刚开始写博客有不足之处大家多多体谅

你可能感兴趣的:(IDEA创建springboot聚合项目)