【发布时间】:2018-12-16 05:43:09
【问题描述】:
我在主类上添加了注释,如下所示:
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 信息 7832 --- [主要] com.main.MainClass : 开始 MainClass DESKTOP-551C51M PID 7832 (C:\Users\sparsh\eclipse-workspace\firstprogram\target\classes 开始 通过 C:\Users\sparsh\eclipse-workspace\firstprogram 中的 sparsh) 2018-07-08 14:16:27.327 信息 7832 --- [主要] com.main.MainClass :没有活动的配置文件集, 回退到默认配置文件:默认 2018-07-08 14:16:27.382 信息 7832 --- [主要] ConfigServletWebServerApplicationContext : 刷新 org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2893de87: 启动日期 [Sun Jul 08 14:16:27 IST 2018];上下文层次的根 2018-07-08 14:16:27.611 警告 7832 --- [主要] ConfigServletWebServerApplicationContext:遇到异常 在上下文初始化期间 - 取消刷新尝试: org.springframework.context.ApplicationContextException:无法 启动网络服务器;嵌套异常是 org.springframework.context.ApplicationContextException:无法 由于缺少启动 ServletWebServerApplicationContext ServletWebServerFactory bean。 2018-07-08 14:16:27.974 错误 7832 --- [ main] os.boot.SpringApplication : 应用程序运行 失败
org.springframework.context.ApplicationContextException:无法 启动网络服务器;嵌套异常是 org.springframework.context.ApplicationContextException:无法 由于缺少启动 ServletWebServerApplicationContext ServletWebServerFactory bean。在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] 在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] 在 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] 在 com.main.MainClass.main(MainClass.java:21) [classes/:na] 原因: org.springframework.context.ApplicationContextException:无法 由于缺少启动 ServletWebServerApplicationContext ServletWebServerFactory bean。在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:204) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] 在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:178) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] 在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] ... 8个常用框架 省略
【问题讨论】:
-
你能发布 pom.xml 吗?
-
下面的答案解决了兄弟,谢谢
标签: java spring maven spring-boot