extdirectspring icon indicating copy to clipboard operation
extdirectspring copied to clipboard

buildAndCacheApiString method sometimes fails to read bean names

Open JozsefGuyas opened this issue 8 months ago • 11 comments

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.

JozsefGuyas avatar Jun 12 '25 08:06 JozsefGuyas

I will take a look. What Spring version do you use in your project?

ralscha avatar Jun 12 '25 10:06 ralscha

@ralscha Thank you for a rapid answer. We are useing spring boot 3.2.11 and ralscha 2.0.0

JozsefGuyas avatar Jun 12 '25 11:06 JozsefGuyas

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 avatar Jun 18 '25 07:06 ralscha

@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 avatar Jun 18 '25 09:06 JozsefGuyas

@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 avatar Jun 18 '25 12:06 ralscha

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

Image

JozsefGuyas avatar Jun 20 '25 13:06 JozsefGuyas

@JozsefGuyas In that case it might be best to remove the caching.

ralscha avatar Jun 20 '25 14:06 ralscha

@JozsefGuyas Released version 2.1.3. No more cache in /api

ralscha avatar Jun 20 '25 14:06 ralscha

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

Image

JozsefGuyas avatar Jun 30 '25 06:06 JozsefGuyas

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

ralscha avatar Jun 30 '25 07:06 ralscha

@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 avatar Jun 30 '25 08:06 ralscha

@ralscha Thank you for quick fix. I have tried it, It's worked!

JozsefGuyas avatar Jul 06 '25 10:07 JozsefGuyas