From c28e1ddcb62732430d4917bdf28860d53476588c Mon Sep 17 00:00:00 2001 From: musketyr Date: Wed, 25 Oct 2023 16:11:31 +0200 Subject: [PATCH] minimal Grails 5.x support --- .../micronaut/grails/MicronautGrailsApp.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/subprojects/micronaut-grails/src/main/java/com/agorapulse/micronaut/grails/MicronautGrailsApp.java b/subprojects/micronaut-grails/src/main/java/com/agorapulse/micronaut/grails/MicronautGrailsApp.java index c5542843..2cedb3d3 100644 --- a/subprojects/micronaut-grails/src/main/java/com/agorapulse/micronaut/grails/MicronautGrailsApp.java +++ b/subprojects/micronaut-grails/src/main/java/com/agorapulse/micronaut/grails/MicronautGrailsApp.java @@ -35,6 +35,7 @@ import org.springframework.core.env.ConfigurableEnvironment; import javax.annotation.Nonnull; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -208,6 +209,7 @@ protected void configureEnvironment(ConfigurableEnvironment environment, String[ @Override protected ConfigurableApplicationContext createApplicationContext() { setAllowBeanDefinitionOverriding(true); + enableCircularReferencesIfSupported(); ConfigurableApplicationContext applicationContext = createSpringApplicationContext(); @@ -258,4 +260,16 @@ private MicronautGrailsAutoConfiguration getApplication() { } } + + public void enableCircularReferencesIfSupported() { + try { + // Get the setAllowCircularReferences method by reflection + Method method = GrailsApp.class.getMethod("setAllowCircularReferences", boolean.class); + method.invoke(this, true); // "this" is the current instance of YourClass + } catch (NoSuchMethodException e) { + LOGGER.info("setAllowCircularReferences method is not present in the current version of the library. Skipping the setup."); + } catch (Exception e) { + LOGGER.error("Failed to invoke setAllowCircularReferences method", e); + } + } }