springwebflux

@Value for resource not working in Webflux


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?


Solution

  • 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.