'Bean failiing to initialize in a not deterministic way
I have a Spring Boot application that has the following bean:
@Configuration
public class ConfigStatus {
@Value("${olt.id}")
private int olt_id;
@Bean
Status createStatus() {
return new Status(olt_id);
}
}
I launch several containers with this application (20 to be exact) and in some of them the bean fails to be initialized and I don't understand why. The bean is successfuly initialized consistently in 18 of 20 containers. Memory is not an issued as the system I am using has 125gb of ram and at the time of this issue is has 90gb of free memory.
This is the class that makes use of the bean:
@DependsOn("createStatus")
@Service
public class ReceiveMessageHandler {
Logger log = LoggerFactory.getLogger(this.getClass().getName());
private static final Gson converter = new Gson();
@Autowired private Status currentStatus;
public void handleMessage(String body) {
OltRequest request = converter.fromJson(body, OltRequest.class);
request.setStartedBeingProcessedAtOlt(new Date().getTime());
Response r = new Response(request.getId(), 200, new Date().getTime());
r.setRequestEnqueuedAtOlt(currentStatus.getEnqueuedAtWorkerTimes().get(request.getId())); // line that fails due to the bean being equal to null
r.setRequestDequeuedAtOlt(new Date().getTime());
log.info("Processing request: " + request.getId());
try {
Thread.sleep(request.getDuration());
} catch(InterruptedException e) {
e.printStackTrace();
}
request.setEndedBeingProcessedAtOlt(new Date().getTime());
log.info("Finished processing request: " + request.getId());
r.setEndedHandling(new Date().getTime());
Worker.send_response(r, request.getOriginMessage().getWorker());
}
}
The error messages sais that when the bean was accessed it was null.
In the environment I have another Spring Boot app with 30 running docker containers in which this problem does not occurr, ence my disbelief :D.
Solution 1:[1]
All it required json_decode , exactly as below .
$comments = json_decode($request->cashoutexpenses, true);
Earlier i was using only json_decode along with one parameter without true keyword which was not working
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yashima |
