簡體   English   中英

Spring Boot不使用領事屬性

[英]spring boot not using consul properties

我有一個這樣注釋的應用程序

@SpringBootApplication(exclude = {DefaultNotificationServiceConfig.class})
@EnableDiscoveryClient
@EnableSwagger2
@EnableSpringDataWebSupport
@EnableJpaRepositories(basePackages = {"com.repositories.jpa"})
@EnableMongoRepositories(basePackages = {"com.repositories.mongo"})
public class DemoApplication {

    private static ApplicationContext ctx;

    public static void main(String[] args) {
        ctx = SpringApplication.run(new Object[]{DemoApplication.class}, args);
        System.out.println(ctx.getEnvironment());
    }

}

我希望它使用consul,並且它正在從consul獲取活動配置文件,因為啟動它時我在日志中看到此行

2016-09-19 20:38:29.947  INFO 9556 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='consul', propertySources=[ConsulPropertySource [name='com/app/'], ConsulPropertySource [name='com/application/']]]
2016-09-19 20:38:29.975  INFO 9556 --- [           main] com.Application           : The following profiles are active: dev,im3

但是,它不使用我在開發配置文件中指定的mongo和mysql數據庫。 它試圖連接到本地主機上的mongo db,這不是我的屬性中的那個

Caused by: com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=localhost:27017

和liquibase正在嘗試使用未在我的屬性中列出的默認數據庫

INFO 9/19/16 8:38 PM: liquibase: Creating database history table with name: PUBLIC.DATABASECHANGELOG

這是領事的開發資料

server:
  port: 8090
spring:
  redis:
    host: ubuntu
    port: 6379
  data:
    mongodb:
      uri: mongodb://ubuntu:27017/test
  datasource:
    url: jdbc:mysql://ubuntu:3309/test
    username: uesr
    password: password
    driverClassName: com.mysql.jdbc.Driver
    testOnBorrow: true
    validationQuery: select 1
multipart:
  maxFileSize: 250MB
  maxRequestSize: 250MB

我有另一個Spring Boot應用程序指向相同的領事實例,並使用相同的配置文件,並且正在運行。 我的類路徑中也有bootstrap.yml

spring:
  application:
    name: ${APPLICATION_NAME:app}
  cloud:
    consul:
      host: ${CONSUL_HOST:localhost}
      port: ${CONSUL_PORT:8500}
      config:
        format: YAML
        watch:
          delay: 10
        prefix: app

我正在使用eclipse,在運行配置中,當啟動如下所示的應用程序時,我正在使用依賴項目中的主類,但是我正在運行的項目是包含上面應用程序類的項目。

@SpringBootApplication(exclude = {DefaultNotificationServiceConfig.class})
@EnableSpringDataWebSupport
@EnableDiscoveryClient
@EnableSwagger2
@EnableJpaRepositories(basePackages = {"com.repositories.jpa"})
@EnableMongoRepositories(basePackages = {"com.repositories.mongo"})
public class Application {

    private static ApplicationContext ctx;

    public static void main(String[] args) throws Exception {
        TimeZone.setDefault(TimeZone.getTimeZone("Etc/UTC"));
        ctx = SpringApplication.run(new Object[]{Application.class}, args);
        System.out.println(ctx);
    }
}

更新正在運行的應用程序會說明日志中正在使用的配置文件

2016-09-19 23:53:55.265  INFO 9744 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='consul', propertySources=[ConsulPropertySource [name='com/app,im3/'], ConsulPropertySource [name='com/app,dev/'], ConsulPropertySource [name='com/app/'], ConsulPropertySource [name='com/application,im3/'], ConsulPropertySource [name='com/application,dev/'], ConsulPropertySource [name='com/application/']]]

我在領事,com / app和com / app,dev和com / app,im3中有3個配置文件。 com / app看起來像這樣

server:
  session:
    timeout: 600
spring: 
  profiles:
    active: dev,im3
  jpa:  
    hibernate: 
      ddl-auto: none
      naming-strategy: com.config.OracleNamingStrategy
    show-sql: false
  thymeleaf:
    mode: LEGACYHTML5
logging:
  level:
    org:
      springframework: ERROR
      thymeleaf: ERROR
      hibernate: ERROR
    springfox: ERROR
    com:
      bosch:
        mercurio: DEBUG

愚蠢的錯誤,我定義了環境變量,但沒有定義VM參數

-Dspring.profiles.active=dev,im3

如果我刪除它不起作用

spring: 
  profiles:
    active: dev,im3

從com / app看來,我既需要

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM