sofastack / sofa-boot

SOFABoot is a framework that enhances Spring Boot and fully compatible with it, provides readiness check, class isolation, etc.
https://www.sofastack.tech/sofa-boot/docs/Home
Apache License 2.0
4.92k stars 1.26k forks source link

初步使用异常 #1302

Closed MorganArthur closed 2 months ago

MorganArthur commented 3 months ago

初步使用sofaboot,项目无法启动

sofa版本:4.0.0/4.1.0

jdk:17

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <!-- 配置文件处理器 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- web 模块 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- 健康检查 模块 -->
        <dependency>
            <groupId>com.alipay.sofa</groupId>
            <artifactId>healthcheck-sofa-boot-starter</artifactId>
            <version>3.22.0</version>
        </dependency>
        <!-- SofaBootRunner 以及 SofaJUnit4Runner 模块 -->
        <dependency>
            <groupId>com.alipay.sofa</groupId>
            <artifactId>test-sofa-boot-starter</artifactId>
        </dependency>
        <!--runtime 依赖-->
        <dependency>
            <groupId>com.alipay.sofa</groupId>
            <artifactId>runtime-sofa-boot-starter</artifactId>
        </dependency>
    </dependencies>
# 服务端口
server.port=8000
# 服务名称
spring.application.name=SOFABoot Demo
# 日志路径
logging.file.path=D:\\logs\\arthur-sofa\\arthur-demo
# 健康检查
management.endpoint.health.show-details=always

项目只依赖了这些依赖包,健康检查依赖没有4.0的版本,我强制依赖的是3.22.0,启动后报如下错误。

2024-03-25T15:04:20.464+08:00  INFO 12124 --- [           main] com.arthur.soft.demo.DemoApplication     : Starting DemoApplication using Java 17.0.6 with PID 12124 (D:\0LYC\WORKSPACE\0GIT\arthur-sofa\sofa-demo\target\production\sofa-demo started by Lenovo in D:\0LYC\WORKSPACE\0GIT\arthur-sofa)
2024-03-25T15:04:20.467+08:00  INFO 12124 --- [           main] com.arthur.soft.demo.DemoApplication     : No active profile set, falling back to 1 default profile: "default"
2024-03-25T15:04:20.555+08:00  WARN 12124 --- [           main] o.s.boot.SpringApplication               : Error handling failed (ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@37eeec90, started on Mon Mar 25 15:04:20 CST 2024)
2024-03-25T15:04:20.588+08:00 ERROR 12124 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.core.env.MissingRequiredPropertiesException: The following properties were declared as required but could not be resolved: [spring.application.name]
    at org.springframework.core.env.AbstractPropertyResolver.validateRequiredProperties(AbstractPropertyResolver.java:145) ~[spring-core-6.0.13.jar:6.0.13]
    at org.springframework.core.env.AbstractEnvironment.validateRequiredProperties(AbstractEnvironment.java:536) ~[spring-core-6.0.13.jar:6.0.13]
    at org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:671) ~[spring-context-6.0.13.jar:6.0.13]
    at org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext.prepareRefresh(AnnotationConfigServletWebServerApplicationContext.java:195) ~[spring-boot-3.1.5.jar:3.1.5]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-6.0.13.jar:6.0.13]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.1.5.jar:3.1.5]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:738) ~[spring-boot-3.1.5.jar:3.1.5]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:440) ~[spring-boot-3.1.5.jar:3.1.5]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-3.1.5.jar:3.1.5]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-3.1.5.jar:3.1.5]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-3.1.5.jar:3.1.5]
    at com.arthur.soft.demo.DemoApplication.main(DemoApplication.java:13) ~[sofa-demo/:na]

2024-03-25T15:04:20.594+08:00  WARN 12124 --- [           main] o.s.boot.SpringApplication               : Unable to close ApplicationContext

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@37eeec90, started on Mon Mar 25 15:04:20 CST 2024
    at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:466) ~[spring-context-6.0.13.jar:6.0.13]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:445) ~[spring-context-6.0.13.jar:6.0.13]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-6.0.13.jar:6.0.13]
    at org.springframework.boot.availability.AvailabilityChangeEvent.publish(AvailabilityChangeEvent.java:92) ~[spring-boot-3.1.5.jar:3.1.5]
    at org.springframework.boot.availability.AvailabilityChangeEvent.publish(AvailabilityChangeEvent.java:78) ~[spring-boot-3.1.5.jar:3.1.5]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.doClose(ServletWebServerApplicationContext.java:171) ~[spring-boot-3.1.5.jar:3.1.5]
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1035) ~[spring-context-6.0.13.jar:6.0.13]
    at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:790) ~[spring-boot-3.1.5.jar:3.1.5]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:329) ~[spring-boot-3.1.5.jar:3.1.5]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-3.1.5.jar:3.1.5]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-3.1.5.jar:3.1.5]
    at com.arthur.soft.demo.DemoApplication.main(DemoApplication.java:13) ~[sofa-demo/:na]

Exception in thread "SpringApplicationShutdownHook" java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@37eeec90, started on Mon Mar 25 15:04:20 CST 2024
    at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:466)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:445)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378)
    at org.springframework.boot.availability.AvailabilityChangeEvent.publish(AvailabilityChangeEvent.java:92)
    at org.springframework.boot.availability.AvailabilityChangeEvent.publish(AvailabilityChangeEvent.java:78)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.doClose(ServletWebServerApplicationContext.java:171)
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1035)
    at org.springframework.boot.SpringApplicationShutdownHook.closeAndWait(SpringApplicationShutdownHook.java:145)
    at java.base/java.lang.Iterable.forEach(Iterable.java:75)
    at org.springframework.boot.SpringApplicationShutdownHook.run(SpringApplicationShutdownHook.java:114)
    at java.base/java.lang.Thread.run(Thread.java:833)
HzjNeverStop commented 3 months ago

在sofaboot4 版本,健康检查依赖被统一至了新的依赖中,你需要替换为

<dependency>
          <groupId>com.alipay.sofa</groupId>
          <artifactId>actuator-sofa-boot-starter</artifactId>
 </dependency>
HzjNeverStop commented 3 months ago

另外,你需要在 application.properties 文件里配置 spring.application.name

MorganArthur commented 3 months ago

初步使用sofaboot,项目无法启动

sofa版本:4.0.0/4.1.0

jdk:17

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <!-- 配置文件处理器 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- web 模块 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- 健康检查 模块 -->
        <dependency>
            <groupId>com.alipay.sofa</groupId>
            <artifactId>healthcheck-sofa-boot-starter</artifactId>
            <version>3.22.0</version>
        </dependency>
        <!-- SofaBootRunner 以及 SofaJUnit4Runner 模块 -->
        <dependency>
            <groupId>com.alipay.sofa</groupId>
            <artifactId>test-sofa-boot-starter</artifactId>
        </dependency>
        <!--runtime 依赖-->
        <dependency>
            <groupId>com.alipay.sofa</groupId>
            <artifactId>runtime-sofa-boot-starter</artifactId>
        </dependency>
    </dependencies>
# 服务端口
server.port=8000
# 服务名称
spring.application.name=SOFABoot Demo
# 日志路径
logging.file.path=D:\\logs\\arthur-sofa\\arthur-demo
# 健康检查
management.endpoint.health.show-details=always

项目只依赖了这些依赖包,健康检查依赖没有4.0的版本,我强制依赖的是3.22.0,启动后报如下错误。

2024-03-25T15:04:20.464+08:00  INFO 12124 --- [           main] com.arthur.soft.demo.DemoApplication     : Starting DemoApplication using Java 17.0.6 with PID 12124 (D:\0LYC\WORKSPACE\0GIT\arthur-sofa\sofa-demo\target\production\sofa-demo started by Lenovo in D:\0LYC\WORKSPACE\0GIT\arthur-sofa)
2024-03-25T15:04:20.467+08:00  INFO 12124 --- [           main] com.arthur.soft.demo.DemoApplication     : No active profile set, falling back to 1 default profile: "default"
2024-03-25T15:04:20.555+08:00  WARN 12124 --- [           main] o.s.boot.SpringApplication               : Error handling failed (ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@37eeec90, started on Mon Mar 25 15:04:20 CST 2024)
2024-03-25T15:04:20.588+08:00 ERROR 12124 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.core.env.MissingRequiredPropertiesException: The following properties were declared as required but could not be resolved: [spring.application.name]
  at org.springframework.core.env.AbstractPropertyResolver.validateRequiredProperties(AbstractPropertyResolver.java:145) ~[spring-core-6.0.13.jar:6.0.13]
  at org.springframework.core.env.AbstractEnvironment.validateRequiredProperties(AbstractEnvironment.java:536) ~[spring-core-6.0.13.jar:6.0.13]
  at org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:671) ~[spring-context-6.0.13.jar:6.0.13]
  at org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext.prepareRefresh(AnnotationConfigServletWebServerApplicationContext.java:195) ~[spring-boot-3.1.5.jar:3.1.5]
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-6.0.13.jar:6.0.13]
  at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.1.5.jar:3.1.5]
  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:738) ~[spring-boot-3.1.5.jar:3.1.5]
  at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:440) ~[spring-boot-3.1.5.jar:3.1.5]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-3.1.5.jar:3.1.5]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-3.1.5.jar:3.1.5]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-3.1.5.jar:3.1.5]
  at com.arthur.soft.demo.DemoApplication.main(DemoApplication.java:13) ~[sofa-demo/:na]

2024-03-25T15:04:20.594+08:00  WARN 12124 --- [           main] o.s.boot.SpringApplication               : Unable to close ApplicationContext

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@37eeec90, started on Mon Mar 25 15:04:20 CST 2024
  at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:466) ~[spring-context-6.0.13.jar:6.0.13]
  at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:445) ~[spring-context-6.0.13.jar:6.0.13]
  at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-6.0.13.jar:6.0.13]
  at org.springframework.boot.availability.AvailabilityChangeEvent.publish(AvailabilityChangeEvent.java:92) ~[spring-boot-3.1.5.jar:3.1.5]
  at org.springframework.boot.availability.AvailabilityChangeEvent.publish(AvailabilityChangeEvent.java:78) ~[spring-boot-3.1.5.jar:3.1.5]
  at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.doClose(ServletWebServerApplicationContext.java:171) ~[spring-boot-3.1.5.jar:3.1.5]
  at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1035) ~[spring-context-6.0.13.jar:6.0.13]
  at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:790) ~[spring-boot-3.1.5.jar:3.1.5]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:329) ~[spring-boot-3.1.5.jar:3.1.5]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-3.1.5.jar:3.1.5]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-3.1.5.jar:3.1.5]
  at com.arthur.soft.demo.DemoApplication.main(DemoApplication.java:13) ~[sofa-demo/:na]

Exception in thread "SpringApplicationShutdownHook" java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@37eeec90, started on Mon Mar 25 15:04:20 CST 2024
  at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:466)
  at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:445)
  at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378)
  at org.springframework.boot.availability.AvailabilityChangeEvent.publish(AvailabilityChangeEvent.java:92)
  at org.springframework.boot.availability.AvailabilityChangeEvent.publish(AvailabilityChangeEvent.java:78)
  at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.doClose(ServletWebServerApplicationContext.java:171)
  at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1035)
  at org.springframework.boot.SpringApplicationShutdownHook.closeAndWait(SpringApplicationShutdownHook.java:145)
  at java.base/java.lang.Iterable.forEach(Iterable.java:75)
  at org.springframework.boot.SpringApplicationShutdownHook.run(SpringApplicationShutdownHook.java:114)
  at java.base/java.lang.Thread.run(Thread.java:833)

我application.properties加了spring.application.name了的

MorganArthur commented 3 months ago

我注释掉sofa相关依赖,改为spring-boot-dependencies,项目可以正常起来

MorganArthur commented 3 months ago

我尝试打了个包,发现打包目录里有两个jar包,一个是sofa-demo-0.0.1-SNAPSHOT.jar,一个是sofa-demo-0.0.1-SNAPSHOT-ark-biz.jar,我使用java -jar的命令,带后缀-ark-biz的包可以正常运行,但是ide工具无法运行,这个不知道是什么问题

HzjNeverStop commented 3 months ago

我注释掉sofa相关依赖,改为spring-boot-dependencies,项目可以正常起来

方便把可复现的代码发布到 git 上分享一下吗

MorganArthur commented 3 months ago

我尝试加了一下下边注释里的内容,然后又取消注释,mvn package啥的,又清缓存,之后莫名其妙又启动起来了。现在都能正常启动了。

image

但是看文档ark相关的需要额外去依赖才行,但是我看这个情况好像默认就有ark了,我搜pom.xml里级联依赖也没有ark的依赖包。

CrazyHZM commented 2 months ago

@MorganArthur 这个还有问题吗?

MorganArthur commented 2 months ago

目前没问题了