首页 新闻 赞助 找找看

springcloud config 找不到本地配置

0
悬赏园豆:30 [已解决问题] 解决于 2021-10-10 10:45

使用cloud config 本地化配置,项目匹配不上对应的配置文件

使用boot版本2.2.6.RELEASE cloud版本:2.2.0.RELEASE

cloud config 配置信息

bootstrap.yml

spring:
  application:
    name: basilan-config
  profiles:
    active: native
  cloud:
    config:
      server:
        native:
          search-locations: classpath:/config
          add-label-locations: false
  security:
    user:
      name: basilan
      password: basilan123
server:
  port: 7686
  servlet:
    context-path: /

config
-- basilan-web-boss
  -- basilan-web-boss-dev.yml

server:
  port: 8888
spring:
  application:
    name: basilan-web-boss
eureka:
  client:
    service-url:
      defaultZone: http://basilan:basilan123@localhost:9080/eureka

配置中心测试

http://127.0.0.1:7686/basilan-web-boss/basilan-web-boss-dev
{
"name": "basilan-web-boss",
"profiles": [
"basilan-web-boss-dev"
],
"label": null,
"version": null,
"state": null,
"propertySources": []
}

http://127.0.0.1:7686/basilan-web-boss/basilan-web-boss-dev.yml
{}

basilan-web-boss项目配置

bootstrap.yml
spring:
  application:
    name: basilan-web-boss
  profiles:
    active: dev

bootstrap-dev.yml
spring:
  cloud:
    config:
      uri: http://basilan:basilan123@127.0.0.1:7686
      profile: dev
      fail-fast: true
      label: basilan-web-boss

启动找不到配置文件

Fetching config from server at : http://127.0.0.1:7686
: Located environment: name=basilan-web-boss, profiles=[basilan-web-boss-dev], label=basilan-web-boss, version=null, state=null
: The following profiles are active: dev
: Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
: BeanFactory id=604c73f2-3f16-3216-b246-c721917bd3b3
: Bean 'com.basilan.web.boss.feign.IPermissionFeign' of type [org.springframework.cloud.openfeign.FeignClientFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
: Tomcat initialized with port(s): 8080 (http)
: Starting service [Tomcat]
: Starting Servlet engine: [Apache Tomcat/9.0.33]
: Initializing Spring embedded WebApplicationContext
: Root WebApplicationContext: initialization completed in 1062 ms
: No URLs will be polled as dynamic configuration sources.
: To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
: DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration@5db3d57c
: No URLs will be polled as dynamic configuration sources.
: To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
: Initializing ExecutorService 'applicationTaskExecutor'
: Eureka HTTP Client uses Jersey
: You already have RibbonLoadBalancerClient on your classpath. It will be used by default. As Spring Cloud Ribbon is in maintenance mode. We recommend switching to BlockingLoadBalancerClient instead. In order to use it, set the value of `spring.cloud.loadbalancer.ribbon.enabled` to `false` or remove spring-cloud-starter-netflix-ribbon from your project.
: Exposing 2 endpoint(s) beneath base path '/actuator'
: Setting initial instance status as: STARTING
: Initializing Eureka in region us-east-1
: Using JSON encoding codec LegacyJacksonJson
: Using XML encoding codec XStreamXml
: Using XML decoding codec XStreamXml
: Resolving eureka endpoints via configuration
: Disable delta property : false
: Single vip registry refresh property : null
: Force full registry fetch : false
: Application is null : false
: Registered Applications size is zero : true
: Application version is -1: true
: Getting all instance registry info from the eureka server
: Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eureka/}, exception=java.net.ConnectException: Connection refused (Connection refused) stacktrace=com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused (Connection refused)
	at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187)

正常应该找到配置为8888的端口,而项目启动使用的是默认的8080,默认的eureka

哪位大神指点下错在哪里?

ysloong的主页 ysloong | 初学一级 | 园豆:176
提问于:2021-10-10 09:40
< >
分享
最佳答案
0

配置文件路径不对

配置中心
config
-- basilan-web-boss-dev.yml
--删掉上级工程目录,测试通过

日志

Fetching config from server at : http://127.0.0.1:7686
: Located environment: name=basilan-web-boss, profiles=[dev], label=basilan-web-boss, version=null, state=null
: Located property source: [BootstrapPropertySource {name='bootstrapProperties-classpath:/config/basilan-web-boss-dev.yml'}]
: The following profiles are active: dev
: Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
: BeanFactory id=604c73f2-3f16-3216-b246-c721917bd3b3
: Bean 'com.basilan.web.boss.feign.ICacheFeign' of type [org.springframework.cloud.openfeign.FeignClientFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
: Bean 'com.basilan.web.boss.feign.IPermissionFeign' of type [org.springframework.cloud.openfeign.FeignClientFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
: Tomcat initialized with port(s): 8888 (http)

重复配置

这个配置也没用到,删除了
  servlet:
    context-path: /
ysloong | 初学一级 |园豆:176 | 2021-10-10 10:42
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册