• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

1K
Views
Spring Boot no puede leer application.properties en Docker

Spring Boot no lee las propiedades de la aplicación cuando se ejecuta en el contenedor Docker.

Mi aplicación.yml

 server: port: 8080 context-path: /mail custom: greeting: Hello YML

Dockerfile

 FROM java:8-jre VOLUME /tmp COPY ./mail.jar /app/mail.jar RUN sh -c 'touch /app/mail.jar' ENV JAVA_OPTS="" ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app/mail.jar" ] EXPOSE 8080

Y un simple ApplicationController

 @RestController public class ApplicationController { private final Environment environment; @Autowired public ApplicationController(Environment environment) { this.environment = environment; } @RequestMapping(path = "/") public Hello hello() { final Hello hello = new Hello(); hello.setGreeting(environment.getProperty("custom.greeting")); return hello; } }

Estoy usando el complemento IntelliJ Docker que asigna automáticamente los puertos 8080 (docker): 18080 (host) y hace que la aplicación esté disponible en http://localhost:18080

Estibador

  1. La propiedad server.context-path no se aplica. La aplicación aún está disponible con / y no con /mail/
  2. La propiedad custom.greeting no se lee del archivo de propiedades y el controlador devuelve {"saludo":null} en su lugar {"saludo":"Hola YML"}

Sin ventana acoplable

  1. ruta de contexto aplicada correctamente

  2. La propiedad custom.greeting devuelve el controlador correctamente

about 3 years ago · Santiago Trujillo
3 answers
Answer question

0

Debe agregar el archivo application.properties en el directorio docker /app/. La estructura del directorio de la ventana acoplable será

 app -main.jar -application.properties

Puede hacerlo usando ADD /ur/local/location/application.properties /app/application.properties

Entonces mejor escribe este comando en tu archivo docker

 ENTRYPOINT ["java" ,"-Djava.security.egd=file:/dev/./urandom --spring.config.location=classpath:file:/app/application-properties","-jar","/app/main.jar"]

Todo su dockerFile debería verse así:

 FROM java:8-jre VOLUME /tmp COPY ./mail.jar /app/mail.jar ADD /ur/local/location/application.properties /app/application.properties ENTRYPOINT ["java" ,"-Djava.security.egd=file:/dev/./urandom --spring.config.location=classpath:file:/app/application-properties","-jar","/app/main.jar"] EXPOSE 8080
about 3 years ago · Santiago Trujillo Report

0

Cambie el nombre de Application.yml a application.yml. Es con referencia al nombre utilizado en los comentarios como Application.yml.

Application.yml funciona bien con viudas pero se rompe dentro de los contenedores de Linux.

about 3 years ago · Santiago Trujillo Report

0

Para la ruta de contexto, debe agregar la ruta de contexto en el archivo de propiedades. dentro de application-default.properties :

server.servlet.contextPath=/miContexto

Luego construye tu proyecto,

mvn instalación limpia

Luego crea una imagen acoplable y ejecuta esa imagen.

about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error