SpringBoot2.4.5和Java11的模块系统问题
在上面的示例中,我在类路径上有spring.boot.starter.web,但应用程序启动失败。如果我添加org.apache.tomcat.embed.core,那么应用程序将成功启动 当我这样配置module-info.java时SpringBoot2.4.5和Java11的模块系统问题,java,spring,spring-boot,Java,Spring,Spring Boot,在上面的示例中,我在类路径上有spring.boot.starter.web,但应用程序启动失败。如果我添加org.apache.tomcat.embed.core,那么应用程序将成功启动 当我这样配置module-info.java时 requires spring.boot; requires spring.boot.autoconfigure; requires spring.web; requires spring.boot.starter.web; 2021-05-20 10:56:
requires spring.boot;
requires spring.boot.autoconfigure;
requires spring.web;
requires spring.boot.starter.web;
2021-05-20 10:56:09.501 INFO 17112 --- [ main] com.example.police.PoliceApplication : Starting PoliceApplication using Java 11 on zhaozhiguang-pc with PID 17112 (D:\item\police\target\classes started by zhaozhiguang in D:\item\police)
2021-05-20 10:56:09.501 INFO 17112 --- [ main] com.example.police.PoliceApplication : No active profile set, falling back to default profiles: default
2021-05-20 10:56:10.565 INFO 17112 --- [ main] com.example.police.PoliceApplication : Started PoliceApplication in 1.435 seconds (JVM running for 3.153)
Process finished with exit code 0
我猜Tomcat没有开机
或
这个成功了
2021-05-20 10:57:48.097 INFO 13740 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-05-20 10:57:48.334 INFO 13740 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2021-05-20 10:57:48.381 INFO 13740 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-05-20 10:57:48.396 INFO 13740 --- [ main] com.example.police.PoliceApplication : Started PoliceApplication in 2.001 seconds (JVM running for 3.202)
2021-05-20 10:57:48.846 INFO 13740 --- [)-192.168.1.107] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-05-20 10:57:48.846 INFO 13740 --- [)-192.168.1.107] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2021-05-20 10:57:48.847 INFO 13740 --- [)-192.168.1.107] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
为什么?
spring.boot.starter.web依赖于org.apache.tomcat.embed.core?spring boot的主要功能之一是自动配置,这意味着它可以配置可用的功能 然而,对于Java模块,“可用”不仅取决于类路径上的jar,还取决于使用
requires
语句授予的访问权限
如果没有requires
语句,Spring Boot的自动配置将无法看到Tomcat,因此它甚至不会尝试配置它
结果:自动忽略该功能。Spring Boot的一个主要功能是自动配置,这意味着它可以配置可用的功能 然而,对于Java模块,“可用”不仅取决于类路径上的jar,还取决于使用
requires
语句授予的访问权限
如果没有requires
语句,Spring Boot的自动配置将无法看到Tomcat,因此它甚至不会尝试配置它
结果:自动忽略该功能。谢谢,那么我需要做什么?我还将使用其他JAR或功能,我可能不知道出了什么问题,对吧。这个add“requires org.apache.tomcat.embed.core”是我在其他地方找到的,谢谢,那么我需要做什么呢?我还将使用其他JAR或功能,我可能不知道出了什么问题,对吧。这个添加“requires org.apache.tomcat.embed.core”是我在其他地方找到的
2021-05-20 10:57:48.097 INFO 13740 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-05-20 10:57:48.334 INFO 13740 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2021-05-20 10:57:48.381 INFO 13740 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-05-20 10:57:48.396 INFO 13740 --- [ main] com.example.police.PoliceApplication : Started PoliceApplication in 2.001 seconds (JVM running for 3.202)
2021-05-20 10:57:48.846 INFO 13740 --- [)-192.168.1.107] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-05-20 10:57:48.846 INFO 13740 --- [)-192.168.1.107] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2021-05-20 10:57:48.847 INFO 13740 --- [)-192.168.1.107] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms