简体   繁体   English

java.lang.ClassCastException:class org.springframework.web.servlet.DispatcherServlet 无法转换为 class jakarta.servlet.Servlet

[英]java.lang.ClassCastException: class org.springframework.web.servlet.DispatcherServlet cannot be cast to class jakarta.servlet.Servlet

I've seen answers to questions similar to mine, but I've tried everything, the error doesn't go away.我已经看到了与我类似的问题的答案,但我已经尝试了所有方法,错误并没有消失 go 。 I understand that the api servlet classes are loaded by two different class loaders because there are multiple sources in the web deployment assembly.我了解到 api servlet 类由两个不同的 class 加载器加载,因为 web 部署程序集中有多个源。 I tried to remove that with servlet-api-3.0-alpha-1.jar, but if I remove the same package from WEB-INF\lib folder, it gives me more errors.我尝试使用 servlet-api-3.0-alpha-1.jar 删除它,但如果我从 WEB-INF\lib 文件夹中删除相同的 package,它会给我更多错误。 There is also to add that it is a spring project imported into eclipse, I had created a web dynamic project which I then converted into a maven project.还要补充一点,它是导入eclipse的spring项目,我创建了一个web动态项目,然后转换成maven项目。 Since by debugging, I discovered that the embedded server was not running the updated jsp pages for me, I changed the project to mvc so as to have the normal server in eclipse. The server is tomcat 10, I can't figure out which packages it loads from maven and which ones from the lib folder.由于通过调试,我发现嵌入式服务器没有为我运行更新的jsp页面,我将项目更改为mvc以便在eclipse中拥有正常的服务器。服务器是tomcat 10,我不知道是哪些包它从 maven 加载,哪些从 lib 文件夹加载。

if I delete from lib servlet-api-3.0-alpha-1.jar, the error appears to me: The type javax.servlet.ServletContext cannot be resolved.如果我从 lib servlet-api-3.0-alpha-1.jar 中删除,我会看到错误:无法解析类型 javax.servlet.ServletContext。 It is indirectly referenced from required.class files MyInitializer.java间接引用自required.class文件MyInitializer.java

If I delete from lib jakarta.el-5.0-M1.jar, the error appears to me: The project cannot be built until build path errors are resolved如果我从 lib jakarta.el-5.0-M1.jar 中删除,我会看到错误:The project cannot be build until build path errors are resolved

Project 'Parlamento' is missing required library: 'C:\Users\segreteria\Desktop\WORKSPACE 4\Parlamento\src\main\webapp\WEB-INF\lib\jakarta.el-5.0.0-M1.jar' “Parlamento”项目缺少所需的库:“C:\Users\segreteria\Desktop\WORKSPACE 4\Parlamento\src\main\webapp\WEB-INF\lib\jakarta.el-5.0.0-M1.jar”

if I downgrade tomcat from 10 to 9, i have to change also the spring version because tomcat 9 doesn't support version 5, and then i have to change all the jar packages.如果我将 tomcat 从 10 降级到 9,我还必须更改 spring 版本,因为 tomcat 9 不支持版本 5,然后我必须更改所有 jar 包。

if i use tomcat 9.0.62 then i have to use spring 4 so i have to use applicationContext.xml which throws other errors which is fixed in later versions of tomcat and this brings me back to update spring packages again.如果我使用 tomcat 9.0.62 那么我必须使用 spring 4 所以我必须使用 applicationContext.xml 抛出其他错误,这些错误在 tomcat 的更高版本中修复,这让我再次更新 spring 包。

STACKTRACE:堆栈跟踪:

SEVERE: Allocate exception for servlet [Parlamento]
java.lang.ClassCastException: class org.springframework.web.servlet.DispatcherServlet 
cannot be cast to class jakarta.servlet.Servlet 
(org.springframework.web.servlet.DispatcherServlet is in unnamed module of loader 
org.apache.catalina.loader.ParallelWebappClassLoader @1601e47; 
jakarta.servlet.Servlet is in unnamed module of loader java.net.URLClassLoader 
 @6bdf28bb)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1071)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:789)
at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:128)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at 
org.apache.catalina.authenticator.AuthenticatorBase.invoke(
AuthenticatorBase.java:542)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:119)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at 
org.apache.catalina.valves.AbstractAccessLogValve.invoke
(AbstractAccessLogValve.java:690)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:356)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process
(AbstractProtocol.java:867)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun
(NioEndpoint.java:1762)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker
(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:833)

网络部署程序集

pom.xml pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.5</version>
   <relativePath></relativePath>
</parent>
<groupId>com.giuggiola</groupId>
<artifactId>Parlamento</artifactId>

  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
<name>Parlamento</name>
<description>Demo project for Spring Boot</description>
<properties>
    <java.version>18</java.version>
</properties>

<dependencies>


<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>

<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-annotations-api</artifactId>
<!--   <version>10.0.23</version>-->
</dependency>


<dependency>
<groupId>jakarta.servlet.jsp.jstl</groupId>
 <artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
<!--  <version>2.0.0</version> -->
<scope>provided</scope>
</dependency>

<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
      <!--    <version>1.2</version> -->
         <scope>provided</scope>
    </dependency>
   

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.1.5.Final</version>
<type>pom</type>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<!--   <version>6.0.0</version> -->
<scope>provided</scope>
</dependency>

 <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
 
    <scope>provided</scope>
</dependency>
 
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
 <!--     <version>4.13.2</version>-->
<scope>provided</scope>

</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
 <!-- <version>5.3.23</version> -->
   <scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
    <groupId>jakarta.servlet</groupId>
    <artifactId>jakarta.servlet-api</artifactId> 
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>jakarta.servlet.jsp</groupId>
    <artifactId>jakarta.servlet.jsp-api</artifactId>
    <version>3.0.0</version>
    <scope>provided</scope>
</dependency>
 
<dependency>
    <groupId>jakarta.el</groupId>
    <artifactId>jakarta.el-api</artifactId>
    <version>4.0.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>jakarta.websocket</groupId>
    <artifactId>jakarta.websocket-api</artifactId>
 <!--  <version>2.0.0</version>  -->  
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>jakarta.security.enterprise</groupId>
    <artifactId>jakarta.security.enterprise-api</artifactId>
    <version>2.0.0</version>
    <scope>provided</scope>
</dependency>


<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<!--    <version>42.5.0</version> --> 
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
 <!--  <version>2.7.3</version>-->
<scope>provided</scope>

</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<!--  <version>2.7.4</version>-->
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<!-- <version>2.7.4</version>-->
<scope>provided</scope>
</dependency>

<dependency>
        <groupId>com.vladmihalcea</groupId>
        <artifactId>hibernate-types-55</artifactId>
        <version>2.14.0</version>
    </dependency>

 </dependencies>

 <build>
 <finalName>Parlamento</finalName>


    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        
        
        <!-- plugin che ho aggiunto io-->
        <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<!--  <version>3.2.0</version> -->
<!--  <scope>provided</scope> -->
</plugin>    
    </plugins>

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

</build>
</project>

lib库

STACKTRACE:堆栈跟踪:

dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version name:   Apache Tomcat/9.0.69
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Nov 9 2022 18:43:47 UTC
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version number: 9.0.69.0
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Windows 8
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            6.2
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             C:\Program Files\Java\jdk- 
17.0.5_windows-x64_bin\jdk-17.0.5
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           17.0.5+9-LTS-191
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         
C:\Users\segreteria\Desktop\WORKSPACE 
4\.metadata\.plugins\org.eclipse.wst.server.core\tmp1
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         C:\Program Files\Apache Software 
Foundation\Tomcat 9.0_Tomcat9.0.69
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: - 
XX:+ShowCodeDetailsInExceptionMessages
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: - 
agentlib:jdwp=transport=dt_socket,suspend=y,address=
localhost:65348
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: - 
javaagent:C:\Users\segreteria\eclipse\jee-2022- 
06\eclipse\configuration\org.eclipse.osgi\407\0\.cp\lib\
javaagent-shaded.jar
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: - 
Dcatalina.base=C:\Users\segreteria\Desktop\WORKSPACE 
4\.metadata\.plugins\org.eclipse.wst.server.core\tmp1
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Program 
Files\Apache Software Foundation\Tomcat 9.0_Tomcat9.0.69
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -  
.deploy=C:\Users\segreteria\Desktop\WORKSPACE 
4\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: --add-opens=java.base/java.lang=ALL- 
UNNAMED
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: --add-opens=java.base/java.io=ALL- 
UNNAMED
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: --add-opens=java.base/java.util=ALL- 
UNNAMED
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: --add- 
opens=java.base/java.util.concurrent=ALL-UNNAMED
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: --add- 
opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
dic 06, 2022 6:13:12 PM 
org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
dic 06, 2022 6:13:13 PM 
org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The Apache Tomcat Native library which allows using OpenSSL 
was not found on the java.library.path: [C:\Program 
Files\Java\jdk-17.0.5_windows-x64_bin\jdk- 
17.0.5\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:
Windows;C:\Program Files\Common 
Files\Oracle\Java\javapath;C:\Program Files (x86)\Common 
Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;
C:\Windows\System32\Wbem;C:\Windows\System32\
WindowsPowerShell\v1.0\;C:\Maven\apache-maven-3.8.6- 
bin\bin;C:\Program Files\Java\jdk-17.0.5_windows-x64_bin\jdk- 
17.0.5\bin;;C:\Users\segreteria\AppData\Local\Programs\Microsoft 
VS Code\bin;C:\Program Files\Java\jdk-17.0.5_windows-x64_bin\jdk- 
17.0.5\bin;.]
dic 06, 2022 6:13:14 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8088"]
dic 06, 2022 6:13:15 PM org.apache.catalina.startup.Catalina load
INFO: Server initialization in [5346] milliseconds
dic 06, 2022 6:13:15 PM org.apache.catalina.core.StandardService 
startInternal
INFO: Starting service [Catalina]
dic 06, 2022 6:13:15 PM org.apache.catalina.core.StandardEngine 
startInternal
INFO: Starting Servlet engine: [Apache Tomcat/9.0.69]
dic 06, 2022 6:13:18 PM org.apache.jasper.servlet.TldScanner 
scanJars
INFO: At least one JAR was scanned for TLDs yet contained no 
TLDs. Enable debug logging for this logger for a complete list of 
JARs that were scanned but no TLDs were found in them. Skipping 
unneeded JARs during scanning can improve startup time and JSP 
compilation time.
dic 06, 2022 6:13:18 PM 
org.apache.catalina.util.SessionIdGeneratorBase 
createSecureRandom
WARNING: Creation of SecureRandom instance for session ID 
generation using [SHA1PRNG] took [122] milliseconds.
dic 06, 2022 6:13:26 PM org.apache.jasper.servlet.TldScanner 
scanJars
INFO: At least one JAR was scanned for TLDs yet contained no 
TLDs. Enable debug logging for this logger for a complete list of 
JARs that were scanned but no TLDs were found in them. Skipping 
unneeded JARs during scanning can improve startup time and JSP 
compilation time.

Spring 5 doesn't support Tomcat 10 but it runs perfectly fine on Tomcat 9. Spring 5 不支持 Tomcat 10 但它在 Tomcat 9 上运行得很好。

In fact I just tested it by creating a simple project with your slightly fixed POM and running it on Tomcat 9.0.69.事实上,我只是通过使用稍微固定的 POM 创建一个简单项目并在 Tomcat 9.0.69 上运行它来测试它。

Here's the POM:这是 POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.6</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    
    <groupId>com.example</groupId>
    <artifactId>tomcat-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>tomcat-demo</name>
    <description>Demo project for Spring Boot</description>
    
    <properties>
        <java.version>17</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-annotations-api</artifactId>
            <!--   <version>10.0.23</version>-->
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>jstl-api</artifactId>
            <version>1.2</version>
            <!--  <version>2.0.0</version> -->
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <!--    <version>1.2</version> -->
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate.orm</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>6.1.5.Final</version>
            <type>pom</type>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <!--   <version>6.0.0</version> -->
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>

            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <!--     <version>4.13.2</version>-->
            <scope>provided</scope>

        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <!-- <version>5.3.23</version> -->
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.2</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>el-api</artifactId>
            <version>2.2</version>
            <scope>provided</scope>
        </dependency>
        
        <dependency>
            <groupId>javax.websocket</groupId>
            <artifactId>javax.websocket-api</artifactId>
            <!--  <version>2.0.0</version>  -->
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.security.enterprise</groupId>
            <artifactId>javax.security.enterprise-api</artifactId>
            <version>1.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <!--    <version>42.5.0</version> -->
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <!--  <version>2.7.3</version>-->
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
            <!--  <version>2.7.4</version>-->
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot</artifactId>
            <!-- <version>2.7.4</version>-->
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.vladmihalcea</groupId>
            <artifactId>hibernate-types-55</artifactId>
            <version>2.14.0</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <!--  <version>3.2.0</version> -->
                <!--  <scope>provided</scope> -->
            </plugin>
        </plugins>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

</project>

Another thing to note is that there must be an implementation of SpringBootServletInitializer in your project to initialize the Servlet context required by Tomcat. You can either make your @SpringBootApplication (or any @Configuration ) extend SpringBootServletInitializer or make it a separate class:另一件需要注意的事情是,您的项目中必须有一个SpringBootServletInitializer的实现来初始化 Tomcat 所需的 Servlet 上下文。您可以使您的@SpringBootApplication (或任何@Configuration )扩展SpringBootServletInitializer或使其成为一个单独的 class:

public class ServletInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(YourSpringBootApplication.class);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ClassCastException:org.springframework.web.servlet.DispatcherServlet无法转换为javax.servlet.Servlet - ClassCastException: org.springframework.web.servlet.DispatcherServlet cannot be cast to javax.servlet.Servlet 实例化servlet类org.springframework.web.servlet.DispatcherServlet时出错 - Error instantiating servlet class org.springframework.web.servlet.Dispatcherservlet java.lang.ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet - java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet java.lang.classnotfoundexception org.springframework.web.servlet.dispatcherservlet - java.lang.classnotfoundexception org.springframework.web.servlet.dispatcherservlet 找不到类:org.springframework.web.servlet.DispatcherServlet - Class Not found : org.springframework.web.servlet.DispatcherServlet org.springframework.web.servlet.DispatcherServlet class 未找到 - org.springframework.web.servlet.DispatcherServlet class not found javax.servlet.ServletException: 错误实例化 servlet class org.springframework.web.servlet.DispatcherServlet - javax.servlet.ServletException: Error instantiating servlet class org.springframework.web.servlet.DispatcherServlet 找不到org.springframework.web.servlet.DispatcherServlet - org.springframework.web.servlet.DispatcherServlet Not Found org.springframework.web.servlet.DispatcherServlet noHandlerFound - org.springframework.web.servlet.DispatcherServlet noHandlerFound java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet 和 org.springframework.beans.factory.Aware - java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet and org.springframework.beans.factory.Aware
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM