Home > database >  @Value for resource not working in Webflux
@Value for resource not working in Webflux

Time:02-10

I have a Spring Boot Webflux app with:

@Value("classpath:file.json")
private Resource create;

The file is in resources/file.json, but create is always coming up null in the debugger.

I have also tried:

new ClassPathLoader("file.json") through manual loading and its working fine.

Any ideas why @Value can't resolve?

CodePudding user response:

Dependency injections happen after the initializers run on a class, that includes constructors. Dependencies are available as initialized within all instance methods as well as in a special lifecycle method marked @PostConstruct. Within a constructor, dependencies have their default values.

  • Related