I would like to learn some new stuff with java 9+ like modules.
So I created a spring boot application with spring-boot-starter-web
and module-info.java
:
module com.example.demo {
requires spring.boot;
requires spring.boot.autoconfigure;
exports com.example.demo;
opens com.example.demo;
}
I used
-> Java 15.0.2
-> Spring Boot 2.4.3
-> IntelliJ IDE 2020.3
-> Ubuntu 20.04.2 LTS
To run the application I use a run button(green arrow) in IntelliJ - default run without any additional params. And the problem is that when I try to run the application, the embedded tomcat server does not start.
Output with module-info.java
2021-03-12 08:57:12.182 INFO 4843 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication using Java 15.0.2 on vagrant-VirtualBox with PID 4843
2021-03-12 08:57:12.184 INFO 4843 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2021-03-12 08:57:13.081 INFO 4843 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 1.511 seconds (JVM running for 3.418)
But, when I remove module-info.java
, everything is ok, and the tomcat server started.
Output without module-info.java
2021-03-12 09:01:49.627 INFO 4928 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication using Java 15.0.2 on vagrant-VirtualBox with PID 4928
2021-03-12 09:01:49.633 INFO 4928 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2021-03-12 09:01:50.897 INFO 4928 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-03-12 09:01:50.912 INFO 4928 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-03-12 09:01:50.912 INFO 4928 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.43]
2021-03-12 09:01:50.958 INFO 4928 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-03-12 09:01:50.958 INFO 4928 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1188 ms
2021-03-12 09:01:51.179 INFO 4928 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-03-12 09:01:51.320 INFO 4928 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-03-12 09:01:51.329 INFO 4928 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 2.271 seconds (JVM running for 3.774)
I'm wondering the difference between outputs. When I use module-info.java
Tomcat doesn't run because it is beyond my module?
What can I do to run app?
How do you think, is it make sense to use java modules with Spring Boot? Why? Why not?
You need to add requires org.apache.tomcat.embed.core;
in modules-info.java to include org.apache.catalina.startup.Tomcat.class
, see this article for details on how Spring boot start the tomcat server.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.