gpt4 book ai didi

java - Springboot : startup issue(missing ServletWebServerFactory bean)

转载 作者:行者123 更新时间:2023-12-02 11:02:21 25 4
gpt4 key购买 nike

我在主类上添加了注释,如下所示:

package com.main;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.CrossOrigin;

import com.controller.RequestClass;

@CrossOrigin(origins = "http://localhost:4200")
@SpringBootApplication
@Configuration
@EnableAutoConfiguration
@ComponentScan("com.*")
public class MainClass
{
public static void main(String[] args)
{
SpringApplication.run(RequestClass.class, args);
}
}

但是在运行应用程序时,遇到以下错误。

如果需要任何其他文件进行调试,请告诉我

2018-07-08 14:16:27.321 INFO 7832 --- [ main] com.main.MainClass : Starting MainClass on DESKTOP-551C51M with PID 7832 (C:\Users\sparsh\eclipse-workspace\firstprogram\target\classes started by sparsh in C:\Users\sparsh\eclipse-workspace\firstprogram) 2018-07-08 14:16:27.327 INFO 7832 --- [ main] com.main.MainClass : No active profile set, falling back to default profiles: default 2018-07-08 14:16:27.382 INFO 7832 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2893de87: startup date [Sun Jul 08 14:16:27 IST 2018]; root of context hierarchy 2018-07-08 14:16:27.611 WARN 7832 --- [ 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. 2018-07-08 14:16:27.974 ERROR 7832 --- [ 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:155) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at com.main.MainClass.main(MainClass.java:21) [classes/:na] Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:204) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:178) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] ... 8 common frames omitted

最佳答案

如果 springapplicatiom.run 针对主类而不是 Controller 类会发生什么 - 它会启动吗?看看这个帖子https://stackoverflow.com/a/44466367/5126865 (我假设了一些你想要实现的目标,所以如果偏离目标,我深表歉意)

关于java - Springboot : startup issue(missing ServletWebServerFactory bean),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51230310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com