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

我正在构建一个Spring Boot" title="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);

}

}

我该如何解决我的问题?

回答:

尝试

@Bean

public SomeService getSomeService(@Value("${property.key}") String key) throws IOException {

return new SomeService(key);

}

以上是 Spring Boot:在@Bean带注释的方法中获取命令行参数 的全部内容, 来源链接: utcz.com/qa/398715.html

回到顶部