'Spring boot in docker does not see classes annotated with profile

I have some classes that supposed to be initialized only on production environment, thus i have added profile annotations to them.

@RestController
@RequestMapping("/authenticate")
@Profile(value = {"development", "production"})
public class AuthenticationController

And in the application.properties file, i'm setting it as:

spring.profiles.active=production

This approach works for me on outside of the container, but in docker, i see these classes are not initializing even I'm setting the right profile on docker-compose.yml:

services:
  web:
    image: johndoe/readingisgood
    build: .
    environment:
      - "SPRING_PROFILES_ACTIVE=production"
    ports:
      - "8080:8080"
    command: --spring.profiles.active=production
    depends_on:
      - MongoDB

And even i see the following message on the logs of the container.

The following 1 profile is active: "production"

Dockerfile:

FROM adoptopenjdk:11
ARG JAR_FILE=target/ReadingIsGood-0.0.1-SNAPSHOT.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

Any ideas?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source