Reputation: 97
I run spring boot application with a single argument - filename. The file contains some properties I need in runtime.
When the application starts it checks if args.length==1
But I need this file (properties) in a single point - @Component
annotated bean.
Is it a way to get an access to the file's content from it?
Upvotes: 7
Views: 2468
Reputation: 1503
In Spring, there is a bean called ApplicationArguments that provides access to the arguments used to run an application.
@Component
public MyComponent {
@Autowired
private ApplicationArguments applicationArguments;
public void method() {
List<String> filenameArgs = applicationArguments.getOptionValues("filename")
}
}
Upvotes: 8