小编典典

Spring Boot:在@Bean带注释的方法中获取命令行参数

spring-boot

我正在构建一个Spring Boot应用程序,需要在用@Bean注释的方法中读取命令行参数。查看示例代码:

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    public SomeService getSomeService() throws IOException {
        return new SomeService(commandLineArgument);
    }
}

我该如何解决我的问题?


阅读 420

收藏
2020-05-30

共1个答案

小编典典

尝试

@Bean
public SomeService getSomeService(@Value("${property.key}") String key) throws IOException {
    return new SomeService(key);
}
2020-05-30