一个内部类不知道是TomcatServletWebServerFactory
但是我的pom文件里有相关的依赖
<dependency>
<groupId>jakarta.servlet.jsp</groupId>
<artifactId>jakarta.servlet.jsp-api</artifactId>
<version>3.1.1</version>
<scope>provided</scope>
</dependency>
@ada; 你可以帮忙么?
父类有你这个方法么?
把这个去掉 provided试试。
<dependency>
<groupId>jakarta.servlet.jsp</groupId>
<artifactId>jakarta.servlet.jsp-api</artifactId>
<version>3.1.1</version>
</dependency>
图二报错提示的很明显了,对应类接收的参数类型,并不是你传入的那种,不是你pom中引入的依赖中的类。
创建Web容器,返回的就是上面提到的WebServer。
public interface ServletWebServerFactory {
WebServer getWebServer(ServletContextInitializer... initializers);
}
ServletContextInitializer入参表示ServletContext的初始化器,用于ServletContext中的一些配置:
public interface ServletContextInitializer {
void onStartup(ServletContext servletContext) throws ServletException;
}
getWebServer会调用ServletContextInitializer#onStartup,即若想在Servlet容器启动时做一些事情,比如注册自己的Servlet,可以实现一个ServletContextInitializer,在Web容器启动时,Spring Boot会把所有实现ServletContextInitializer接口的类收集起来,统一调其onStartup。
对于Tomcat报错缺少软件包的问题,可以按照以下步骤解决:
<dependencies>
...
<dependency>
<groupId>com.example</groupId>
<artifactId>example-package</artifactId>
<version>1.0.0</version>
</dependency>
...
</dependencies>
mvn clean install
如果以上方法都尝试过了,但问题仍然存在,可能需要进一步检查其他可能的原因并采取相应的解决方法。此时,可以通过提供更多的问题细节和错误日志来获取更准确的帮助。