sofastack / sofa-serverless

a framework to enabe app architecture evolve from monolithic to microservices smoothly by involving modular and macroservices architecture.
https://sofaserverless.gitee.io/home/
Apache License 2.0
115 stars 41 forks source link

普通 SpringBoot 改造成基座报错 #109

Closed lvjing2 closed 11 months ago

lvjing2 commented 12 months ago

Describe the question or bug

普通 SpringBoot 改造成基座,照理只需要引入如下依赖即可。

<properties>
        <sofa.serverless.runtime.version>0.1.2</sofa.serverless.runtime.version>
</properties>

<dependency>
    <groupId>com.alipay.sofa.serverless</groupId>
    <artifactId>sofa-serverless-runtime-starter</artifactId>
    <version>${sofa.serverless.runtime.version}</version>
</dependency>

但是只引入该依赖,会报错 image

Expect behavior

不会报错

Steps to reproduce

  1. 新建 SpringBoot,可以通过 Spring initilizer
  2. application.properties 里增加 spring.application.name=${换成实际应用名},否则会报这个错误 image
  3. pom.xml 里增加
    <properties>
        <sofa.serverless.runtime.version>0.1.2</sofa.serverless.runtime.version>
    </properties>
<dependencies>
        <dependency>
            <groupId>com.alipay.sofa.serverless</groupId>
            <artifactId>sofa-serverless-runtime-starter</artifactId>
            <version>${sofa.serverless.runtime.version}</version>
        </dependency>
</dependencies>
  1. 启动参数里增加 -Dsofa.ark.embed.enable=true
  2. 启动应用

    修复方式

pom 里添加 actuator 依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

原因

SOFAServerless 基座runtime 里 arklet 部分强依赖了 actuator,需要基座里主动增加该依赖。

问题影响

对于基座改造会有额外的依赖,使得基座的改造不能纯粹引入我们的 runtime starter 完成初始化。

修复方式

Arklet 里对 actuator 的依赖,改成自动识别的方式,如果基座里有 actuator 才执行 health 那段逻辑。

lvjing2 commented 11 months ago

当前先认为 actuator 是 arklet 必带能力,可以 compile 依赖进来。所以不需改动代码