Я работаю над примером Springboot и получаю ApplicationContextException - PullRequest
0 голосов
/ 17 марта 2020

Я использовал другую версию tomcat и iam, получая ошибку как Невозможно запустить ServletWebServerApplicationContext из-за отсутствия компонента ServletWebServerFactory. я получаю вышеупомянутую ошибку при запуске, любая быстрая помощь?

Ошибка

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.5.RELEASE)

2020-03-16 23:04:01.268  INFO 3452 --- [           main] c.example.demo.CoursesWebappApplication  : Starting CoursesWebappApplication on DESKTOP-10R8SDT with PID 3452 (D:\workspace-spring-tool-suite-4-4.5.1.RELEASE\CoursesWebapp\target\classes started by admin in D:\workspace-spring-tool-suite-4-4.5.1.RELEASE\CoursesWebapp)
2020-03-16 23:04:01.268  INFO 3452 --- [           main] c.example.demo.CoursesWebappApplication  : No active profile set, falling back to default profiles: default
2020-03-16 23:04:01.581  WARN 3452 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
2020-03-16 23:04:01.596 ERROR 3452 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:156) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]

ControllerClass

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");
        }
    }

DemoClass

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

<?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.2.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>CoursesWebapp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>CoursesWebapp</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies><dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Ответы [ 2 ]

2 голосов
/ 17 марта 2020

Полагаю, вы используете загрузку Spring, поэтому используйте @SpringBootApplication вместо @SpringBootConfiguration, чтобы убедиться, что Spring предоставляет все необходимые автоконфигурации для вашего проекта.

0 голосов
/ 17 марта 2020

Просто измените аннотацию в главном классе на @ SpringBootApplication из @ SpringBootConfiguration , чтобы Spring автоматически сконфигурировал все компоненты, необходимые для запуска приложения.

@SpringBootApplication
public class CoursesWebappApplication {

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

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...