这里我是采用gradle来管理jar包的。
1、使用idea创建一个gradle项目。
2、编辑settings.gradle文件
rootProject.name = 'jtm'
//include 'jtm_core'
//include 'jtm_sys'
//include 'jtm_eureka'
def dir = new File(settingsDir.toString())
def projects = new HashSet()
def projectSymbol = File.separator + 'src'
dir.eachDirRecurse { subDir ->
def subDirName = subDir.canonicalPath
def isSubProject = true
if (subDirName.endsWith(projectSymbol)) {
for (String projectDir in projects) {
if (subDirName.startsWith(projectDir)) {
isSubProject = false
break
}
}
if (isSubProject) {
projects << subDirName
def lastIndex = subDirName.lastIndexOf(projectSymbol)
def gradleModulePath = subDirName.substring(dir.canonicalPath.length(), lastIndex).replace(File.separator, ':')
println "include " + gradleModulePath
include gradleModulePath
}
}
}
3、编辑build.gradle文件
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
springCloudVersion = 'Finchley.SR1'
}
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
allprojects {
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group 'com.dqcer'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
mavenCentral()
}
dependencies {
testCompile('org.springframework.boot:spring-boot-starter-test')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
}
4、在当前项目中新建子项目jtm_eureka
5、修改子项目中的build.gradle文件
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-server')
}
6、在子项目中添加配置文件后,运行。
报错:
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
Caused by: java.net.ConnectException: Connection refused: connect
网上查阅资料后,更改子项目中的配置文件yml如下:
server: port: 9001 servlet: context-path: /eurekaeureka: instance: hostname: localhost client: fetch-registry: false register-with-eureka: false service-url: defaultZone: http://${eureka.instance.hostname}:${server.port}${server.servlet.context-path}
再次运行,还是这个错,网上说将main方法的注解改了、驼峰名称,或者jar缺失等。都试过。并没有什么作用。冷静查看输入日志发现端口号是8080
多次尝试后得出结论,配置文件名必须为application.yml,不然程序找不到,就会默认配置后,不管如何发现并没有什么用。