2016-09-19 81 views
0

我有一个应用程序注释这样春天启动不使用领事性能

@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()); 
    } 

} 

我想使用的领事,它正从领事主动配置文件,因为我看到在日志中该行开始时

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 

但是它没有使用我在dev配置文件中指定的mongo和mysql数据库。它试图将一个在我的属性

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 

连接到蒙戈DB在本地主机这是不是和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: 
    application: 
    name: ${APPLICATION_NAME:app} 
    cloud: 
    consul: 
     host: ${CONSUL_HOST:localhost} 
     port: ${CONSUL_PORT:8500} 
     config: 
     format: YAML 
     watch: 
      delay: 10 
     prefix: app 

我使用Eclipse和在运行配置我使用的是从一个相关项目的主类开始看起来像下面的应用程序时bootstrap.yml,但该项目我我正在运行的是包含上述应用程序类的项目。

@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/']]] 

我在领事3个配置文件,COM /应用程序和COM /应用程序,开发和COM /应用程序,IM3。 COM /应用程序看起来像这样

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 
+0

没有多大意义,一个人会工作,而另一个不是。没有什么明显的跳出来。也许你有一个小样本来重现问题? – spencergibb

+0

它似乎配置文件是活动的,但他们没有被使用 – gary69

+0

'/ env'说什么? – spencergibb

回答

1

愚蠢的错误,我定义的环境变量,但不是VM参数

-Dspring.profiles.active=dev,im3 

,如果我从COM删除

spring: 
    profiles: 
    active: dev,im3 

这是行不通的/ app,这似乎是多余的,我需要两个