Skip to content

Commit

Permalink
minimal Grails 5.x support
Browse files Browse the repository at this point in the history
  • Loading branch information
musketyr committed Oct 25, 2023
1 parent 1fe5113 commit c28e1dd
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -208,6 +209,7 @@ protected void configureEnvironment(ConfigurableEnvironment environment, String[
@Override
protected ConfigurableApplicationContext createApplicationContext() {
setAllowBeanDefinitionOverriding(true);
enableCircularReferencesIfSupported();

ConfigurableApplicationContext applicationContext = createSpringApplicationContext();

Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit c28e1dd

Please sign in to comment.