idea+gradle+springboot 多项目

idea+gradle+springboot 多项目创建 by:zrs

创建文件结构

1.创建项目文件根目录文件夹:

many-product
2.在many-product下创建两个文件(注意:文件名一定不能错):
build.gradle 和 settings.gradle
3.在many-product下分别创建两个项目文件:
one-service  和 two-service
4.分别给one-service 和 two-service下创建目录结构
src/main/java
src/main/resources
5.分别给one-service 和 two-service根目录下创建gradle文件
build.gradle
6.分别给src/main/resources目录下创建yml配置文件
application.yml
7.分别给src/main/java创建包文件
com/zrs
8.分别在src/main/java/com/zrs 下创建java文件
OneServiceApplication.java
TwoServiceApplication.java
9.至此,文件结构已经创建完成。完整项目目录结构如下:
many-product
      |--one-service
      |      |--src
      |	     |	  |--main
      |	     |      |--java
      |	     |      |    |--com
      |	     |      |	       |--zrs
      |	     |      |	            `--OneServiceApplication.java
      |	     |      |
      |	     |      |--resources
      |	     |	          `--application.yml
      |	     `--build.gradle
      |--two-service
      |      |--src
      |	     |	  |--main
      |	     |      |--java
      |	     |      |    |--com
      |	     |      |	       |--zrs
      |	     |      |	            `--TwoServiceApplication.java
      |	     |      |
      |	     |      |--resources
      |	     |	          `--application.yml
      |	     `--build.gradle         
      `--build.gradle	     
      |	     
      `--settings.gradle	  

   
---------------------------------目录结构创建结束--------------------------------------------

进行gradle配置:

1.在项目根目录下的gradle.build中配置如下信息:
buildscript{
    ext{
        springBootVersion = '1.5.9.RELEASE'
    }
    repositories{
        jcenter()
        mavenCentral()
    }
    dependencies{
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
apply plugin: 'idea'
repositories{
    jcenter()
    mavenCentral()
}
subprojects{
    buildscript{
        ext{
            springBootVersion = '1.5.9.RELEASE'
        }
        repositories{
            jcenter()
            mavenCentral()
        }
        dependencies{
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        }
    }
    ext{
        springBootVersion = '1.5.9.RELEASE'
    }
    apply plugin: 'idea'
    apply plugin: 'java'
    repositories{
        jcenter()
        mavenCentral()
    }

    dependencies{
        compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
    }
}
2.在settings.gradle中配置如下:
rootProject.name = 'many-product'
include 'one-service'
include 'tow-service'
3.分别在one-service 和 two-service根目录下的build.gradle分别下配置如下:
one-service下配置:
archivesBaseName= 'one-service'
two-service下配置:
archivesBaseName= 'two-service'
4.分别在one-service 和 two-service目录下的application.yml分别下配置启动端口:
one-service下配置:

server:
  port: 8080
two-service下配置:
server:
  port: 8082
5.分别在one-service 和 two-service目录下的java文件中, 注解@SpringBootApplication和配置启动
one-service 如下:
package com.zrs;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class OneServiceApplication {
    public static void main(String[] args){
        SpringApplication.run(OneServiceApplication.class, args);
    }

    @GetMapping("/hello")
    public String hello(){
        return "hello world!!! one";
    }
}
two-service 如下:
package com.zrs;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class TwoServiceApplication {
    public static void main(String[] args){
        SpringApplication.run(TwoServiceApplication.class, args);
    }

    @GetMapping("/hello")
    public String hello(){
        return "hello world!!! two";
    }
}






  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值