Posts

Showing posts with the label autowired

Getting NullPointerException when tried to read @Autowired configuration object [duplicate]

Image
Getting NullPointerException when tried to read @Autowired configuration object [duplicate] This question already has an answer here: I am trying to read some properties from application.properties . I have created a configuration class with @Component and @ConfigurationProperties annotations. application.properties @Component @ConfigurationProperties When I am trying to access the configuration from a controller class, its working fine. But when I am trying to access the configuration from one component class, its throwing a null pointer exception. Following are the application.properties and classes. application.properties application.properties elasticsearch.ip=localhost InputManagementController.java @RestController public class InputManagementController { @Autowired private Configuration configuration; @GetMapping("/crawler/start") public String start(){ try{ System.out.println(configuration.getIp()); ----> getting value localhos...