I'm trying to use @Value annotation and auto-populate my variable from the properties file, but with no luck. Values are not being set and are null.
taskService.java
@Service
public class TaskService {
@Value("${a}")
String aa;
public final RestTemplate restTemplate;
public TaskService(RestTemplateBuilder restTemplateBuilder){
System.out.println("----------xxxxxxxxxxx-------------" +aa);
this.restTemplate = restTemplateBuilder.build();
}
public Task getTask(int taskId) throws TaskDoesNotExistException {
try {
return this.restTemplate.getForObject("/tasks/{taskId}", Task.class, taskId);
} catch (HttpClientErrorException e) {
if(e.getRawStatusCode() == 404)
throw new TaskDoesNotExistException("Task not found", e);
}
return null;
}
}
eventhandler.java
@Component
@RepositoryEventHandler(Application.class)
public class ApplicationRepositoryEventHandler {
@Autowired
TaskService taskService;
@HandleBeforeCreate
public void handleApplicationCreate(Application application) throws TaskDoesNotExistException {
for (Integer taskId: application.getTasks()){
taskService.getTask(taskId);
}
}
}