bootstrap.yml не загружается в Spring Boot 2 - PullRequest
0 голосов
/ 12 июня 2018

Возникла проблема при запуске клиентского приложения с весенней загрузкой, которому необходимо подключиться к серверу конфигурации.Файл bootstrap.yml игнорируется

Сервер конфигурации - это работает!

server:
  port: 8888  

spring:
  application:
    name: configserver
  cloud:
    config:
      server:
       git:
         uri:https://xxxxx@bitbucket.org/eco/properties.git

bootstrap.yml - Клиент конфигурации - Не работает!

spring:
  application:
    name: api
  cloud:
    config:
     uri: http://localhost:8888

Файл bootstrap.yml игнорируется при запуске приложения .

Клиент POM

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.2.RELEASE</version>
</parent>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Finchley.RC2</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<properties>
    <java.version>1.8</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <spring-cloud.version>2.0.0.RC2</spring-cloud.version>
</properties>

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

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

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

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

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
        <version>1.4.4.RELEASE</version>
    </dependency>

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

    <!-- Database dependencies -->
    <dependency>
        <groupId>com.oracle.jdbc</groupId>
        <artifactId>ojdbc7</artifactId>
        <version>12.1.0.2</version>
        <scope>system</scope>
        <systemPath>${basedir}/src/main/resources/lib/ojdbc7-12.1.0.2.jar</systemPath>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.9.0</version>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.9.0</version>
    </dependency>

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.10.19</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-properties-migrator</artifactId>
        <scope>runtime</scope>
    </dependency>
</dependencies>

<build>
    <finalName>api-emissor</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>1.3.5.RELEASE</version>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Клиент основного класса

@SpringBootApplication
@EnableEurekaClient
@EnableAutoConfiguration(exclude = {SecurityAutoConfiguration.class})
@ComponentScan("br.com.eco.api.emissor")
@EnableJpaRepositories("br.com.eco.api.emissor.repository")
@EntityScan("br.com.eco.api.emissor.domain")
public class Application {

public static void main(final String[] args) {
    SpringApplication.run(Application.class, args);
}

}

Почемуbootstrap.yml игнорируется?

Ответы [ 3 ]

0 голосов
/ 14 июня 2018

Вам нужно добавить зависимость для стартера весеннего облака.

0 голосов
/ 20 февраля 2019

Если вы определили spring.config.location, он переопределит все пути к файлам конфигурации, включая путь к bootstrap.yml, поэтому вам придется изменить spring.config.location на spring.config.additional-location.

Так что при запускеПриложение, которое вы должны будете добавить -Dspring.config.additional-location=/path/to/application.yml.

Для получения дополнительной информации проверьте this

0 голосов
/ 14 июня 2018

Вам необходимо указать имя конфигурации, и оно должно совпадать с именем файла конфигурации в службе конфигурации.

spring:
    cloud:
       config:
          name: myService    # myService.yml or myService-[profile].yml( if you have a profile activated).
           uri: http://localhost:8888
...