why spring boot does not load application yml when packaged (With gradle)?

Viewed 1297

Not found anything interesting so far, so here am I, asking a question.

I got a spring boot application, that runs fine. Problem is : custom configuration ! I want it to run on port 8081 (and not default port 8080). So I added the application.yml in the src/main/resources directory, packaged it... And it run on port 8080 When I run the @SpringBootApplication class from intellij, it does run on port 8081 (I just added the application.yml file.) So why ?

It's a gradle multi module project. T added the application.yml file into the module that is actually packaged into a jar file. It is packaged using tha gradle shadow plugin, and does contain the application.yml file at the root of the jar file.

The application.yml is like this :

server:
    port: 8081

I don't really know which information you'll need, so feel free to ask !

Any idea is welcome.

EDIT 1 : "Stacktrace" when I start the server :

java -jar serverApp.jar 

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                        

août 29, 2020 5:50:54 PM org.apache.coyote.AbstractProtocol init
INFOS: Initializing ProtocolHandler ["http-nio-8080"]
août 29, 2020 5:50:54 PM org.apache.catalina.core.StandardService startInternal
INFOS: Starting service [Tomcat]
août 29, 2020 5:50:54 PM org.apache.catalina.core.StandardEngine startInternal
INFOS: Starting Servlet engine: [Apache Tomcat/9.0.37]
août 29, 2020 5:50:54 PM org.apache.catalina.core.ApplicationContext log
INFOS: Initializing Spring embedded WebApplicationContext
août 29, 2020 5:50:55 PM org.apache.coyote.AbstractProtocol start
INFOS: Starting ProtocolHandler ["http-nio-8080"]
2 Answers

Without seeing the actual code, I can recommend 2 things to try.

1- Have you missed to use the argument in main method-

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

2- Try to start the springboot server with arguments-

java -jar -Dserver.port=8081 ServerApplication.jar

It seems that Shadow Plugin is not the right thing to use with Spring Boot according to this comment:

the boot framework has it's own gradle plugin and method for packaging ditributable jar files. I dont' think I would combine shadow and the boot plugin in the same project. They will collide.

and also this.

Related