首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法解析值"${zuul.prefix}“中的占位符'zuul.prefix‘

无法解析值"${zuul.prefix}“中的占位符'zuul.prefix‘
EN

Stack Overflow用户
提问于 2018-11-16 09:56:18
回答 1查看 1.1K关注 0票数 0

我有一个项目,微服务的网关-服务器(Zuul),eureka-服务器与配置服务器的集成.

我有一个git存储库,它具有网关服务器的属性文件(gateway-server-dev.yml)。

网关-服务器-dev.yml文件:

代码语言:javascript
复制
    spring:
    application:
    name: gateway-server

 info:
  component: Gateway Server

endpoints:
 restart:
   enabled: true
 shutdown:
enabled: true
 health:
   sensitive: false



  zuul:
 prefix: /CustomerHub/api
 routes:
   create-customer: 
      path: /create/**
     serviceId: create-customer
   search-customer: 
     path: /search/**
     serviceId: search-customer
   update: 
      path: /update/**
     serviceId: update-customer
   authorization:
     path: /authorization/**
     sensitiveHeaders:
     serviceId: customerhub-authorization      
  host:
       connect-timeout-millis: 5000
       socket-timeout-millis: 10000
        max-total-connections: 10000
       max-per-route-connections: 50
 ribbon:
   eager-load:
     enabled: true

   ribbon:
 ReadTimeout: 60000
 ConnectTimeout: 60000
 MaxAutoRetries: 3
 MaxAutoRetriesNextServer: 3
 restclient:
 enabled: true
      eureka:
       enabled: true



eureka:
  client:
    serviceUrl:
      defaultZone: http://{host}:{port}/eureka
    registerWithEureka: true
  instance:
    preferIpAddress: true  

hystrix:
  threadpool:
    default:
      coreSize: 1000
      maximumSize: 10000
       queueSizeRejectionThreshold: -1
     maxQueueSize: -1
  command:
    default:
      execution:
        isolation:
          strategy: THREAD
         thread:
              timeoutInMilliseconds: 60000

server:
  port: 9000


logging:
  file: /app/logs/aaa_gateway.log
  level:
    org.springframework.web: INFO
    com.customerhub.filters: INFO
    org.hibernate: INFO

customerhub:
  authorization:
    check-token-url: /oauth/check_token   

网关服务器中的引导文件是:

代码语言:javascript
复制
spring.profiles.active=dev
spring.application.name=gateway-server
spring.cloud.config.uri=http://{host}:{port}
management.security.enabled=false
management.endpoints.web.exposure.include=*

现在,当我在本地系统中在eclipse中执行时,它工作正常,并从配置服务器获取属性。

当我通过命令提示符运行同一个jar时,它会给出以下错误:

无法解析值"${zuul.prefix}“中的占位符'zuul.prefix‘

日志文件是:

代码语言:javascript
复制
2018-11-16 15:08:01.523  INFO 8604 --- [ost-startStop-1] 
c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic 
configuration sources, define System property 
archaius.configurationSource.additionalUrls or make config.properties 
available on classpath.
2018-11-16 15:08:01.555  INFO 8604 --- [ost-startStop-1] 
c.netflix.config.DynamicPropertyFactory  : DynamicPropertyFactory is 
initialized with configuration sources: 
com.netflix.config.ConcurrentCompositeConfiguration@ef4443e
2018-11-16 15:08:01.977 ERROR 8604 --- [ost-startStop-1] 
o.s.b.c.embedded.tomcat.TomcatStarter    : Error starting Tomcat context. 
Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. 
Message: Error creating bean with name'org.springframework.cloud.netflix.zuul.ZuulConfiguration$ZuulFilterConfigur 
  ation': Unsatisfied dependency expressed through field 'filters'; nested 
exception is org.springframework.beans.factory.BeanCreationException: Error 
creating bean with name 'preFilter': Injection of autowired dependencies 
failed; nested exception is java.lang.IllegalArgumentException: Could not 
resolve placeholder 'zuul.prefix' in value "${zuul.prefix}"
EN

回答 1

Stack Overflow用户

发布于 2018-11-16 10:20:15

Spring无法找到gateway-server-dev.yml文件,所以使用下面的代码将yml文件添加到类路径中。

代码语言:javascript
复制
@PropertySource("classpath:gateway-server-dev.yml")

或将这些行添加到节下的pom中。

代码语言:javascript
复制
<resource>
     <directory>src/main/resources</directory>
     <filtering>true</filtering>
     <includes>
          <include>**/*.yml</include>
     </includes>
</resource>

参考带弹簧的特性

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53335354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档