1

I noticed that when I create a spring-cloud application it is only getting properties from the application.properties file (or application.yml), so I have created the following demo project to simplify the situation, however, I still couldn't manage to load properties from a bootstrap.propertiles file. I tried converting the bootstrap.properties file into bootstrap.yml with the same result. I tried compiling and running the microservice as standalone with the same result.

I left this project on GitHub to demonstrate the situation: https://github.com/bcfernandez/Mobile-app-ws.git

  • The only entry point available is http://localhost:port/users/status
  • application.properties file is empty.
  • bootstrap.properties file sets server.port as 8181.
  • The application is running on port 8080.

The pom.xml is the following:

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>es.myorg.trm.api.users</groupId>
    <artifactId>TRM_ApiUsers</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>TRM_ApiUsers</name>
    <description>TRM API for Users Management</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>2020.0.0</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>       
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>                   
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-actuator -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>           
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>   
        <!-- https://mvnrepository.com/artifact/org.modelmapper/modelmapper -->
        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>2.3.9</version>
        </dependency>  
        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-boot-starter -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-xml -->
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
        </dependency>       
        <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt -->
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>
        
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>

</project>

Why is this simple project is not working as expected?

BCF
  • 23
  • 1
  • 1
  • 5
  • Welcome to Stack Overflow! Do not vandalize your posts. By posting on this site, you've irrevocably granted the Stack Exchange network the right to distribute that content under the [CC BY-SA 4.0 license](//creativecommons.org/licenses/by-sa/4.0/) for as long as it sees fit to do so. For alternatives to deletion, see: [I've thought better of my question; can I delete it?](https://stackoverflow.com/help/what-to-do-instead-of-deleting-question) – Sabito stands with Ukraine Jan 11 '21 at 17:21
  • https://stackoverflow.com/questions/64994034/bootstrap-yml-configuration-not-processed-anymore-with-spring-cloud-2020-0/65445282#65445282 thanks @BCF for mentioning the link in comments it actually answer your question – user951215 May 14 '21 at 13:34

1 Answers1

0

I took a look at your pom file, you are not creating any springboot cloud project because typically you will find a corresponding Spring Cloud BOM version in pom.xml if you used https://start.spring.io/, like so

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>${spring-cloud.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

That's why the bootstrap file is being dismissed. Here is a number of spring cloud projects you can use.

You can start by:

A. creating a spring cloud config server project

B. Make your actual project the spring cloud config client here is the official tutorial

Sorry If I'm not understanding your question properly, but if you are already created a springcloud project, one possible issue is the version...

Here similar issue was raised on Stack Overflow.

Aschay
  • 356
  • 1
  • 6
  • That section in the pom.xml is already there. – BCF Jan 11 '21 at 15:38
  • Sorry I rechecked and It did NOT have any cloud project in it – Aschay Jan 11 '21 at 17:06
  • 1
    The issue https://stackoverflow.com/questions/64994034/bootstrap-yml-configuration-not-processed-anymore-with-spring-cloud-2020-0/65445282#65445282 has been indeed very useful. Even creating the pom.xml using https://start.spring.io the necessary dependency to activate the bootstrap context was missing. Thanks a LOT. – BCF Jan 11 '21 at 17:18