conlin day 2022-05-27 10:41 采纳率: 0%
浏览 36

spring cloud 2021.0.1 整合log4j2报错

搭建springcloud微服务框架,在网关模块整合log4j2,全局排除spring-boot-starter-logging,引入了spring-boot-starter-log4j2,启动网关报错,说是

Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.

相关代码

<!--全局排除spring-boot-starter-logging内的所有依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

<!--日志-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>
<!-- SpringBoot Actuator -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>



@Slf4j
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
public class xxGatewayApplication {

  public static void main(String[] args) {
    SpringApplication.run(xxGatewayApplication .class, args);
    log.info("~服务网关启动成功~");
  }
}

运行结果及报错内容

05/27 10:27:05465 WARN 1-- AnnotationConfigServletWebServerApplicationContext: 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.
05/27 10:27:05507 ERROR1-- 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:163)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
    at c.c.xxxGatewayApplication.main(ChxtecMicroGatewayApplication.java:21)
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:210)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:180)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160)
    ... 8 more

尝试过的方法

1、使用logback日志没有问题,也就是说不排除spring-boot-starter-logging这个包就没有问题
2、引入tomcat-embed-core,不行
3、引入web,不行

想要达到的结果

使用log4j2,网关正常运行

  • 写回答

1条回答 默认 最新

  • 皮蛋不吃粥 2022-05-27 10:47
    关注

    引入web依赖 其他全删除

    img

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 5月27日

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 基于52单片机的酒精浓度检测系统加继电器和sim800
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答