1

我正在使用 Micronaut GraalVM 应用程序,我创建了一个类来使用@ConfigurationProperties从 application.yml 加载信息,它在我运行我的 jar 应用程序时工作,然后我用它构建了一个本机图像,但我的配置属性类没有'不加载任何信息,我尝试在 --initialize-at-build-time 中添加我的配置属性类,但这都不起作用,这是我的代码:

应用程序.yml

micronaut:
  application:
    name: mngraalvm
team:
  name: 'Steelers'
  color: 'Black'
  player-names:
    - 'Mason Rudolph'
    - 'James Connor'

引擎.java

package com.msc.configurationprop;

public interface Engine {
    String getName();
    String getColor();
}

EngineConfig.java

package com.msc.configurationprop;

import io.micronaut.context.annotation.ConfigurationProperties;

import java.util.List;

@ConfigurationProperties("team")
class EngineConfig {
    private String name;
    private String color;
    private List<String> playerNames;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public List<String> getPlayerNames() {
        return playerNames;
    }

    public void setPlayerNames(List<String> playerNames) {
        this.playerNames = playerNames;
    }

}

EngineImpl.java

package com.msc.configurationprop;

import javax.inject.Singleton;

@Singleton
public class EngineImpl implements Engine {
    private final EngineConfig config;

    public EngineImpl(EngineConfig config) {
        this.config = config;
    }

    public final EngineConfig getConfig() {
        return config;
    }

    @Override
    public String getName() {
        return config.getName();
    }

    @Override
    public String getColor() {
        return config.getColor();
    }
}

家庭控制器.java

@Controller("/home")
public class HomeController {
  private final EngineImpl engineimpml;

  @Get("/team")
  public EngineImpl team() {
      return this.engineimpml;
  }

  public HomeController(@Nullable EngineImpl engineimpml) {
      this.engineimpml = engineimpml;
  }
}

我需要在 Application.java 或其他配置中注入我的 EngineImpl 类吗?谢谢。

4

0 回答 0