当前位置: 首页 > 知识库问答 >
问题:

bootstrap.yml不在Spring Boot 2中加载

吴康平
2023-03-14

在启动需要连接到配置服务器的spring-boot客户端应用程序时,我遇到了一个问题。引导程序。yml文件被忽略

配置服务器 - 这有效!

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

< code>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个答案

翟嘉年
2023-03-14

您必须将此依赖项添加到pom.xml

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
</dependency>
狄旻
2023-03-14

您需要为spring cloud starter添加依赖项。

韶弘壮
2023-03-14

在 Spring 引导配置客户端中添加此依赖项:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
 类似资料:
  • 在我的Spring Boot项目中,我定义了4个配置文件 演示 开发 测试 产品 application-demo.yml 春云拱顶库 错误日志:

  • 我正在尝试使用 https://github.com/spring-projects/spring-security-oauth2-boot 使用本教程:https://docs.spring.io/spring-security-oauth2-boot/docs/current-SNAPSHOT/reference/htmlsingle/ SpringBoot应用程序 服务器初始化器 用户详细信

  • 本文向大家介绍SpringBoot2 JPA解决懒加载异常的问题,包括了SpringBoot2 JPA解决懒加载异常的问题的使用技巧和注意事项,需要的朋友参考一下 jpa解决懒加载异常 在我上一遍文章上进行行修改,SpringBoot2 实现JPA分页和排序分页 实体类上改: 控制器验证 我大概实现了一下,具体的如果大佬找到更好的方法或者发现我的方法是错的,希望各位大佬提醒一下!感谢! 补充:Sp

  • 本文向大家介绍Spring Boot 中application.yml与bootstrap.yml的区别,包括了Spring Boot 中application.yml与bootstrap.yml的区别的使用技巧和注意事项,需要的朋友参考一下 yml与properties 其实yml和properties文件是一样的原理,且一个项目上要么yml或者properties,二选一的存在。 推荐使用ym

  • 本文向大家介绍springboot2版本无法加载静态资源问题解决,包括了springboot2版本无法加载静态资源问题解决的使用技巧和注意事项,需要的朋友参考一下 前言 在学习springboot的过程中,发现无法引用静态资源。我使用的是springboot2.2.1版本。 追溯源码,终于解决。并记录下解决思路。 默认加载路径 首先得知道springboot默认加载得资源路径是什么。 首先我们看W

  • 因此,在我的微服务中,我必须以configserver的短主机名为目标。 但是,当我在没有docker的IDE中本地运行它们时,短主机名无法解析。 因此,我正在寻找一个解决方案,目标不同的配置服务器根据我的环境。