目录
一、IDEA中创建项目
1、在idea中,选择File-->new project。
选择Gradle,取消勾选Java,把一个项目分解为多个微服务架构创建。

2、选择next下一步输入项目名称、路径(根据项目情况,输入相关信息)

3、点击完成,出现如下创建的项目。

二、创建子服务项目
1、创建Module子服务项
鼠标右键点击项目名(springcloud2021),new-->Module,选择Java,如下。

2、点击next(下一项),输入服务名称(com.hongli.admin.service、com.hongli.admin.dao系统权限服务,控制层和数据层分离)。

三、配置项目文件
1、配置settings.gradle文件
把创建的com.hongli.admin.service、com.hongli.admin.dao服务引入项目中

2、配置build.gradle文件
在build.gradle文件用,映入spring boot、Alibaba nacos及相关项目依赖信息。

plugins {
id 'org.springframework.boot' version '2.1.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
ext{
springBootVersion = '2.1.7.RELEASE'
springCloudVersion = 'Greenwich.SR1'
}
repositories {
mavenLocal()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
mavenCentral()
}
configure(allprojects) { project ->
group 'com.runnet'
version '1.0.0'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.8
tasks.withType(JavaCompile) { options.encoding = "UTF-8" }
repositories {
mavenLocal()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
mavenCentral()
}
dependencies {
compile 'com.github.whvcse:easy-captcha:1.6.2'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-amqp', version: '2.1.0.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis', version: '2.3.5.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.1.17.RELEASE'
testCompile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}") {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
}
project("runnet-admin-dao") {
apply plugin: 'maven'
apply plugin: 'maven-publish'
tasks.withType(JavaCompile) { options.encoding = "UTF-8" }
dependencies {
compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.8'
compile group: 'com.google.guava', name: 'guava', version: '24.1-jre'
compile group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-autoconfigure', version: '2.1.3'
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.1')
compile group: 'org.mybatis', name: 'mybatis', version: '3.5.3'
compile group: 'com.baomidou', name: 'mybatis-plus-boot-starter', version: '3.4.0'
compile group: 'com.baomidou', name: 'mybatis-plus-generator', version: '3.4.1'
compile group: 'commons-codec', name: 'commons-codec', version: '1.15'
compile group: 'com.alibaba', name: 'druid', version: '1.2.1'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.22'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
compile "org.projectlombok:lombok:1.18.8"
annotationProcessor 'org.projectlombok:lombok:1.18.8'
testCompile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
testCompile("com.baomidou:mybatis-plus-generator:3.4.1")
testCompile("com.github.davidfantasy:mybatis-plus-generator-ui:1.3.4")
testCompile("org.apache.velocity:velocity-engine-core:2.2")
testCompile("org.springframework.boot:spring-boot-starter-test")
compile('cn.hutool:hutool-all:5.5.7')
}
jar {
manifest.attributes provider: 'gradle'
}
}
project("runnet-admin-service") {
apply plugin: 'org.springframework.boot'
apply plugin: 'maven'
configurations {
compile.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
compile.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
dependencies {
compile project(':runnet-admin-dao')
compile "org.projectlombok:lombok:1.18.8"
compile "nl.bitwalker:UserAgentUtils:1.2.4"
annotationProcessor 'org.projectlombok:lombok:1.18.8'
compile('org.springframework.boot:spring-boot-starter-aop')
compile('com.alibaba:fastjson:1.2.47')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-undertow')
compile('org.springframework.boot:spring-boot-starter-webflux')
compile('com.auth0:java-jwt:3.4.0')
compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.yaml:snakeyaml:1.23')
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
compile group: 'com.alibaba.cloud', name: 'spring-cloud-starter-alibaba-nacos-config', version: '2.1.0.RELEASE'
compile group: 'com.alibaba.cloud', name: 'spring-cloud-starter-alibaba-nacos-discovery', version: '2.1.0.RELEASE'
compile 'com.github.whvcse:easy-captcha:1.6.2'
compile group: 'com.runnet', name: 'runnet-common', version: '1.0.0'
//compile group: 'com.runnet', name: 'runnet-admin-dao', version: '1.0.0'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-log4j2', version: '2.1.17.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis', version: '2.3.5.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.1.17.RELEASE'
}
jar {
manifest.attributes provider: 'gradle'
}
}
project("runnet-rydata-dao") {
apply plugin: 'maven'
apply plugin: 'maven-publish'
tasks.withType(JavaCompile) { options.encoding = "UTF-8" }
dependencies {
compile project(':runnet-admin-dao')
compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.8'
compile group: 'com.google.guava', name: 'guava', version: '24.1-jre'
compile group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-autoconfigure', version: '2.1.3'
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.1')
compile group: 'org.mybatis', name: 'mybatis', version: '3.5.3'
compile group: 'com.baomidou', name: 'mybatis-plus-boot-starter', version: '3.4.0'
compile group: 'commons-codec', name: 'commons-codec', version: '1.15'
compile group: 'com.alibaba', name: 'druid', version: '1.2.1'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.22'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
compile('com.alibaba:fastjson:1.2.47')
compile "org.projectlombok:lombok:1.18.8"
compile group: 'e-iceblue', name: 'spire.doc.free', version: '2.7.3'
annotationProcessor 'org.projectlombok:lombok:1.18.8'
testCompile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
compileOnly group: 'javax.servlet', name: 'servlet-api', version: '2.5'
compile group: 'com.runnet.meteoinfo', name: 'MeteoInfoLib', version: '4.6.11'
implementation group: 'gov.nist.math', name: 'jama', version: '1.0.3'
implementation group: 'org.freemarker', name: 'freemarker', version: '2.3.20'
implementation group: 'com.aspose', name: 'aspose.words', version: '15.8.0'
compile group: 'org.apache.poi', name: 'poi', version: '3.14'
compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.13'
implementation group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
implementation group: 'commons-net', name: 'commons-net', version: '3.3'
}
jar {
manifest.attributes provider: 'gradle'
}
}
project("runnet-rydata-service") {
apply plugin: 'org.springframework.boot'
configurations {
compile.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
compile.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
dependencies {
compile project(':runnet-rydata-dao')
//compile project(':runnet-nhssp-common')
compile("com.runnet:runnet-common:1.0.0")
compile('com.auth0:java-jwt:3.4.0')
compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
//compile fileTree(dir:'lib',includes:['*jar'])
compile('com.alibaba:fastjson:1.2.47')
compile "org.projectlombok:lombok:1.18.8"
annotationProcessor 'org.projectlombok:lombok:1.18.8'
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.1')
compile group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-autoconfigure', version: '2.1.3'
compile group: 'com.alibaba.cloud', name: 'spring-cloud-starter-alibaba-nacos-config', version: '2.1.0.RELEASE'
compile group: 'com.alibaba.cloud', name: 'spring-cloud-starter-alibaba-nacos-discovery', version: '2.1.0.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis', version: '2.4.1'
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-undertow')
compile('org.springframework.boot:spring-boot-starter-webflux')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-log4j2', version: '2.1.17.RELEASE'
}
jar {
manifest.attributes provider: 'gradle'
}
}
dependencies {
implementation 'org.jetbrains:annotations:19.0.0'
}
3、build.gradle配置学习
1、访问https://start.spring.io/,选择及输入相关内容,可点击ADD DEPENDENCIES,查询项目相关依赖。

2、点击EXPLORE弹出页面,选择build.gradle配置

本文档详细介绍了如何在IDEA中利用Gradle创建一个Spring Cloud项目,并一步步指导创建子服务项目,配置settings.gradle和build.gradle文件,以引入Spring Boot和Alibaba Nacos等相关依赖,实现微服务架构的搭建。
&spm=1001.2101.3001.5002&articleId=117030006&d=1&t=3&u=8dce0261c3da4218801697dbd7ff644e)
937

被折叠的 条评论
为什么被折叠?



