简体   繁体   English

将 active profie 设置为“native”,在 spring boot 2 配置服务器中是强制性的

[英]Is setting active profie to "native", mandatory in spring boot 2 config server

I am trying to create an embedded config server in spring boot 2.1.6 version.我正在尝试在 spring boot 2.1.6 版本中创建一个嵌入式配置服务器。 The start-up fails saying:启动失败说:


***************************
APPLICATION FAILED TO START
***************************

Description:

Invalid config server configuration.

Action:

If you are using the git profile, you need to set a Git URI in your configuration.  If you are using a native profile and have spring.cloud.config.server.bootstrap=true, you need to use a composite configuration.

I am not sure spring clearly documents what native profile is, whereas my bootstrap.yml looks like:我不确定 spring 清楚地记录了原生配置文件是什么,而我的 bootstrap.yml 看起来像:

---
spring:
  application:
    name : <name>
  datasource:
    url: <url>
    driver-class-name: oracle.jdbc.OracleDriver
    username: <username>
    password: <password>
    hikari:
      maximum-pool-size: 1
      connection-timeout: 5000
  cloud:
    config:
      server:
        bootstrap: true
        default-label: latest
        jdbc:
          sql: <sql>
          order: 0
  jpa:
    database: Oracle
    show-sql: true
    properties:
      hibernate:
        dialect: org.hibernate.dialect.Oracle10gDialect
  profiles:
    active:
    - jdbc
    - sit

If I add 'native' in the list of active profile the error goes away.如果我在活动配置文件列表中添加“本机”,错误就会消失。
But I am unable to find spring documentation which says,any config server other than git is by default 'native'.但是我找不到 spring 文档,其中说,除 git 之外的任何配置服务器默认都是“本机”。
Is this new addition in spring 2.xx release because I simply upgraded from 1.5.10 version and the system broke.这是spring 2.xx 版本中的新增功能吗,因为我只是从1.5.10 版本升级而系统崩溃了。

So my question is:所以我的问题是:
Is this native profile mandatory from spring 2.xx release thus making it backward in-compatible or there is a work around via which I can skip adding this native profile in my list of active profiles.从 spring 2.xx 版本开始,这个本地配置文件是强制性的,从而使其向后不兼容,或者有一种解决方法,我可以跳过在我的活动配置文件列表中添加这个本地配置文件。
Reference :参考 :
https://cloud.spring.io/spring-cloud-config/2.1.x/multi/multi_spring-cloud-config.html https://cloud.spring.io/spring-cloud-config/2.1.x/multi/multi_spring-cloud-config.html

Not sure if I remember is correctly but I think this question was aimed when database backed config server configuration is used.不确定我记得是否正确,但我认为这个问题是在使用数据库支持的配置服务器配置时针对的。
Solution:解决方案:
inside src/main/resources, create a folder meta-inf & add a file spring.factories.在 src/main/resources 中,创建一个文件夹 meta-inf 并添加一个文件 spring.factories。 Inside this file add below code:在此文件中添加以下代码:

org.springframework.cloud.bootstrap.BootstrapConfiguration=\
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration

Pls let me know if this works请让我知道这是否有效

I faced the same issue after using JDBC backed config server.使用 JDBC 支持的配置服务器后,我遇到了同样的问题。

My issue was with the pom, I was using wrong jdbc dependency.我的问题出在 pom 上,我使用了错误的 jdbc 依赖项。

Instead of :代替 :

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
</dependency>

Use spring starter jdbc :使用 spring 启动器 jdbc :

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM