首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不使用领事属性的弹簧引导

不使用领事属性的弹簧引导
EN

Stack Overflow用户
提问于 2016-09-19 20:58:19
回答 1查看 2.1K关注 0票数 1

我有一个像这样注释的应用程序

代码语言:javascript
复制
@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());
    }

}

我希望它使用领事,它从领事处获取活动概要文件,因为启动时我在日志中看到了这一行。

代码语言:javascript
复制
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数据库。它试图连接到localhost上的mongo db,这不是我的属性中的

代码语言:javascript
复制
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

而液化库正在尝试使用未在我的属性中列出的默认数据库。

代码语言:javascript
复制
INFO 9/19/16 8:38 PM: liquibase: Creating database history table with name: PUBLIC.DATABASECHANGELOG

这是领事提供的开发资料

代码语言:javascript
复制
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引导应用程序,指向相同的领事实例,使用相同的概要文件,并且该配置文件正在工作。我的类路径中也有bootstrap.yml

代码语言:javascript
复制
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,在运行配置中,在启动下面的应用程序时,我使用依赖项目中的一个主类,但我正在运行的项目是包含上面的应用程序类的项目。

代码语言:javascript
复制
@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);
    }
}

更新,该应用程序工作状态在日志中使用的配置文件

代码语言:javascript
复制
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/app和com/app,开发和com/app,im3。com/app如下所示

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-20 15:00:35

愚蠢的错误,我定义了环境变量,但没有定义VM参数。

代码语言:javascript
复制
-Dspring.profiles.active=dev,im3

如果我移除

代码语言:javascript
复制
spring: 
  profiles:
    active: dev,im3

从com/app来看,我需要两者都是多余的。

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

https://stackoverflow.com/questions/39582000

复制
相关文章

相似问题

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