Search code examples
javaspring-bootkotlinamazon-elastic-beanstalk

AWS Beanstalk + Kotlin + Spring boot: NoSuchMethodException main()


I've a Spring Boot app written in Kotlin that I have deployed to AWS Beanstalk that is throwing the following exception:

Exception in thread "main" java.lang.NoSuchMethodException: com.prototype.demo.DemoApplication.main([Ljava.lang.String;)
at java.base/java.lang.Class.getDeclaredMethod(Class.java:2675)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:47)

Locally, when I run the app from IntelliJ I've no issues. I have the spring-boot-maven-plugin and the kotlin-maven-plugin in my project.

Any ideas about what could be causing the issue? I previously built a similar app in Java but didn't run into this issue.

Thank you for your expertise and time.


Update: something interesting to notice is that I had to set in the properties of my POM the following line in order to make the project executable by IntelliJ during development (i had forgotten about it): <start-class>com.prototype.demo.DemoApplication</start-class>

Now I've removed it and I get a different error when running the jar file. I will spend some time on it and see if that's related or not and update the question accordingly. Thank you!


Solution

  • The issue was raised by the following property declared in my POM file: <start-class>com.prototype.demo.DemoApplication</start-class>. Once I removed it and added the open keyword to the Configuration annotated classes and to the DemoApplication(the class containing the main) it finally worked.