buildAndCacheApiString method sometimes fails to read bean names
Description: We encountered a case where the buildAndCacheApiString method in ApiController failed to read the bean names. This caused the generated API to be incomplete or empty.
Possible reasons identified:
- The Spring context might not have been fully initialized when the method was called.
- The methodInfoCache was not populated (e.g., due to initialization issues, empty cache, or incorrect bean scanning).
- The required beans were not registered in the Spring context, or there was a configuration error.
- Filtering by the group parameter resulted in no matching beans.
- An exception occurred during cache population that was not handled.
Steps to reproduce: Unfortunately, the issue is intermittent and not consistently reproducible.
Request: Please investigate potential causes and suggest improvements for more robust bean discovery and error handling in this method. Adding more detailed logging could also help diagnose the problem in the future.
I will take a look. What Spring version do you use in your project?
@ralscha Thank you for a rapid answer. We are useing spring boot 3.2.11 and ralscha 2.0.0
I wonder if there is a possible problem because of the different Spring dependencies. extdirectspring 2.0.0 depends on Spring 6.0.5. Spring Boot 3.2.11 depends on 6.1.14.
Have you tried extdirectspring 2.1.1? This version depends on Spring 6.2.6?
@ralscha I have tried your soulution but the problem is same. I have investegeted this problem, and I found following case. I can call this method ch.ralscha.extdirectspring.controller.ApiController#api() before the ch.ralscha.extdirectspring.controller.MethodRegistrar#onApplicationEvent() have been called.
So I get following answer. Ext.ns('SimiMvClient.serviceApi');SimiMvClient.serviceApi.REMOTING_API = {"url":"/router","type":"remoting","actions":{}}; The actions is emtpy, and remain empty so I have to restart my application!
The ApiCache remain empty.
@JozsefGuyas I released a new version 2.1.2. This version checks in api if the cache is empty. If it is then it tries to populate the cache
@ralscha Thank you for the prompt fix. Unfortunately, it introduced another issue: when the /api.js endpoint is called during initialization, it occasionally results in some beans not being cached.
@JozsefGuyas In that case it might be best to remove the caching.
@JozsefGuyas Released version 2.1.3. No more cache in /api
@ralscha Thank you for the quick fix! I’m afraid the issue still persists. If I call the 'ApiController' before Spring Boot has fully initialized, it sometimes happens that not all beans are included in the 'ApiCache'. I’ve currently solved it by preventing caching until Spring has fully loaded.
@JozsefGuyas I wonder how an application can call an Spring Boot endpoint before the Spring context is fully initialized. Is there a way in Spring Boot to configure this behaviour.
@JozsefGuyas I released a new version (2.1.4). You can now disable caching with the request parameter cache=false
/api.js?cache=false
@ralscha Thank you for quick fix. I have tried it, It's worked!