@SpringBootApplication
public class App {
@Value("${Application}")
private String application;
@Value("${APP_SERVER_CPU_ENABLED}")
private String APP_SERVER_CPU_ENABLED;
@Value("${APP_SERVER_MEMORY_ENABLED}")
private String APP_SERVER_MEMORY_ENABLED;
@Autowired
MonitoringItems mI;
public static void main(String[] args) {
SpringApplication.run(App.class, args);
MonitoringItems mI=null;
try {
System.out.println(APP_SERVER_CPU_ENABLED);
System.out.println(APP_SERVER_MEMORY_ENABLED);
if (APP_SERVER_MEMORY_ENABLED.equalsIgnoreCase("true") && APP_SERVER_CPU_ENABLED.equalsIgnoreCase("true")) {
//do something
}
どのようにメインクラスは@Valueアノテーションを読み取れませんか?私の他のクラスでは、@Configuration、@ComponentScan、@EnableAutoConfigurationをクラスの上に置き、コンストラクタの上に@PostConstructを置く必要があります。そして、私はapplication.propertiesから値を取得することができました。どのように私はメインクラスのためにそれを行うことができるでしょうか?メインクラスで@Valueアノテーションを読み込む方法は?
[おっと、編集コメント]あなたのアプリクラスは春管理Beanではありません。スプリングが静的メンバーに値を設定するかどうかは不明です。 – Taylor