悠扬随风 发表于 2024-6-21 13:31:32

Unable to start ServletWebServerApplicationContext due to missing Serv

https://img-blog.csdnimg.cn/direct/4bb5b5cabcb34e9dbd583b81a995e0dc.png
这个错误信息通常表现在启动 Java 项目时,Spring Boot 应用步伐无法找到或启动嵌入式的 Servlet 容器(例如 Tomcat、Jetty 等)。这可能是由于项目的依赖项配置有问题。以下是一些常见的解决方法:

[*] 查抄依赖项: 确保你的 pom.xml 文件中包罗了 Spring Boot Starter Web 依赖项。你需要确保包罗以下依赖
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

 2.查抄 Spring Boot 版本: 确保你使用的 Spring Boot 版本是兼容的。你可以在 pom.xml 中设置 Spring Boot 版本,例如:
 
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.0</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

3. 确保主类精确配置: 确保你的主类(包罗 main 方法的类)精确地使用了 @SpringBootApplication 注解。例如:
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
      SpringApplication.run(Application.class, args);
    }
}

4.清理并重新构建项目: 有时构建缓存可能会导致问题。实验清理并重新构建项目
    mvn clean install
 
5.查抄应用步伐配置: 确保你的 application.properties 或 application.yml 文件没有配置错误。特别是服务器相关的配置 .

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: Unable to start ServletWebServerApplicationContext due to missing Serv