我正在构建一个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); }