这里我是采用gradle来管理jar包的。
1、使用idea创建一个gradle项目。
2、编辑settings.gradle文件
1rootProject.name = 'jtm' 2//include 'jtm_core' 3//include 'jtm_sys' 4//include 'jtm_eureka' 5 6def dir = new File(settingsDir.toString()) 7def projects = new HashSet() 8def projectSymbol = File.separator + 'src' 9 10dir.eachDirRecurse { subDir -> 11 def subDirName = subDir.canonicalPath 12 def isSubProject = true 13 if (subDirName.endsWith(projectSymbol)) { 14 for (String projectDir in projects) { 15 if (subDirName.startsWith(projectDir)) { 16 isSubProject = false 17 break 18 } 19 } 20 if (isSubProject) { 21 projects << subDirName 22 def lastIndex = subDirName.lastIndexOf(projectSymbol) 23 def gradleModulePath = subDirName.substring(dir.canonicalPath.length(), lastIndex).replace(File.separator, ':') 24 println "include " + gradleModulePath 25 include gradleModulePath 26 } 27 } 28}
3、编辑build.gradle文件
1buildscript { 2 ext { 3 springBootVersion = '2.0.4.RELEASE' 4 springCloudVersion = 'Finchley.SR1' 5 } 6 repositories { 7 maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 8 mavenCentral() 9 } 10 dependencies { 11 classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 12 } 13} 14 15allprojects { 16 apply plugin: 'java' 17 apply plugin: 'idea' 18 apply plugin: 'org.springframework.boot' 19 apply plugin: 'io.spring.dependency-management' 20 21 group 'com.dqcer' 22 version '1.0-SNAPSHOT' 23 sourceCompatibility = 1.8 24 25 repositories { 26 maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 27 mavenCentral() 28 } 29 30 dependencies { 31 testCompile('org.springframework.boot:spring-boot-starter-test') 32 } 33 34 dependencyManagement { 35 imports { 36 mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" 37 } 38 } 39}
4、在当前项目中新建子项目jtm_eureka
5、修改子项目中的build.gradle文件
1dependencies { 2 compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-server') 3}
6、在子项目中添加配置文件后,运行。
报错:
1com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server 2 3Caused 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,不然程序找不到,就会默认配置后,不管如何发现并没有什么用。