最近在启动项目里启动日志如下:
_ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.2.RELEASE)
2021-09-10 17:45:46.118 INFO 42688 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2021-09-10 17:45:48.663 INFO 42688 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available
2021-09-10 17:45:48.663 WARN 42688 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/cure/default/master": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
2021-09-10 17:45:48.666 INFO 42688 --- [ main] com.snszyk.cure.Application : The following profiles are active: dev
2021-09-10 17:45:49.262 WARN 42688 --- [ main] o.m.s.mapper.ClassPathMapperScanner : No MyBatis mapper was found in '[com.snszyk.cure]' package. Please check your configuration.
2021-09-10 17:45:49.327 INFO 42688 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2021-09-10 17:45:49.329 INFO 42688 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2021-09-10 17:45:49.355 INFO 42688 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 9ms. Found 0 repository interfaces.
2021-09-10 17:45:49.782 INFO 42688 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=7df298c5-d1e2-3c50-9a75-d16a0023cdcd
2021-09-10 17:45:49.948 INFO 42688 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$3921e685] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-09-10 17:45:49.979 INFO 42688 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$553be982] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-09-10 17:45:50.476 INFO 42688 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 10020 (http)
2021-09-10 17:45:50.506 INFO 42688 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
而代码中我的Eureka配置为:
eureka:
instance:
prefer-ip-address: true
client:
service-url:
defaultZone: http://admin:admin@localhost:8761/eureka
register-with-eureka: true
spring:
application:
name: cure
profiles:
active:
- dev
cloud:
config:
discovery:
enabled: true
service-id: service-config
label: master
问题:明明已经配置了Eureka为什么出现:
2021-09-10 17:45:46.118 INFO 42688 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2021-09-10 17:45:48.663 INFO 42688 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available
2021-09-10 17:45:48.663 WARN 42688 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/cure/default/master": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
后来发现我的配置文件名为application.yml
面springboot中application.yml是用于配置应用级的。因此这个配置文件是启动后才会加载。
因此需要将这个配置文件改为bootstrap.yml
springboot配置文件加载顺序:
bootstrap.yml(bootstrap.properties)先加载。是系统级别的一些参数配置,这些参数一般是不变的。
application.yml(application.properties)后加载。一般用来定义单个应用级别的,如果搭配 spring-cloud-config 使用 application.yml 里面定义的文件可以实现动态替换
bootstrap.yml 用于应用程序上下文的引导阶段。
bootstrap.yml 由父Spring ApplicationContext加载。父ApplicationContext 被加载到使用 application.yml 的之前。
注意:
一旦bootstrap.yml 被加载,则内容不会被覆盖,即便后期加载的application.yml的内容标签与bootstrap的标签一致,application 也不会覆盖bootstrap.yml, 而application.yml 里面的内容可以动态替换.