Java 我正在研究下面的springboot示例,我得到了ApplicationContextException

Java 我正在研究下面的springboot示例,我得到了ApplicationContextException,java,spring-boot,Java,Spring Boot,由于缺少ServletWebServerFactoryBean,我使用了不同版本的tomcat和iam获取错误,因为无法启动ServletWebServerApplicationContext。 我在启动时遇到上述错误,有什么快速帮助吗 错误 控制器类 package com.example.demo; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation

由于缺少ServletWebServerFactoryBean,我使用了不同版本的tomcat和iam获取错误,因为无法启动ServletWebServerApplicationContext。 我在启动时遇到上述错误,有什么快速帮助吗

错误

控制器类

package com.example.demo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;



    @Controller
    public class CoursesController {
        @RequestMapping(value="/course", method = RequestMethod.GET)
        public void courses () {
            System.out.println("welcome");
        }
    }
民主阶级

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;

@SpringBootConfiguration
public class CoursesWebappApplication {

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

}
pom.xml


4.0.0
org.springframework.boot
spring启动程序父级
2.2.5.1发布
com.example
CoursesWebapp
0.0.1-快照
CoursesWebapp
SpringBoot的演示项目
1.8
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧启动器webflux
org.springframework.boot
春靴起跑服
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
SpringBootStarterWeb服务
org.springframework.boot
弹簧起动试验
测试
org.junit.vintage
朱尼特老式发动机
org.springframework.boot
springbootmaven插件

只需将主类上的注释从@SpringBootConfiguration更改为@SpringBootApplication,这样spring就会自动配置运行应用程序所需的所有内容

@SpringBootApplication
public class CoursesWebappApplication {

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

}

只需将主类上的注释从@SpringBootConfiguration更改为@SpringBootApplication,这样spring将自动配置运行应用程序所需的所有内容

@SpringBootApplication
public class CoursesWebappApplication {

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

}

我想您使用的是Spring boot,所以请使用
@SpringBootApplication
而不是
@SpringBootConfiguration
来确保Spring为您的项目提供所有需要的自动配置。

我想您使用的是Spring boot,因此,请使用
@SpringBootApplication
而不是
@SpringBootConfiguration
,以确保Spring为您的项目提供所有需要的自动配置。

在application.properties set Spring.main.web application type=noneHi中,您能在application.properties set spring.main.web应用程序type=noneHi中尝试一次'@SpringBootApplication'而不是'@SpringBootConfiguration'吗?您能尝试一次'@SpringBootApplication'而不是'@SpringBootConfiguration'吗