Skip to content

Commit

Permalink
Fixes Deploy Grails app to tomcat webapps error
Browse files Browse the repository at this point in the history
Closes gh-37
  • Loading branch information
rainboyan committed Jan 22, 2024
1 parent 33b9dec commit 3eba708
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions grace-boot/src/main/groovy/grails/boot/GrailsBuilder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022 the original author or authors.
* Copyright 2015-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,22 +15,24 @@
*/
package grails.boot;

import io.micronaut.spring.context.MicronautApplicationContext;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;

/**
* Fluent API for constructing Grails instances.
* Simple extension of {@link SpringApplicationBuilder}.
*
* @author Graeme Rocher
* @author Michael Yan
* @since 3.0.6
*/
public class GrailsBuilder extends SpringApplicationBuilder {

private MicronautApplicationContext micronautContext;
private ConfigurableApplicationContext micronautContext;

public GrailsBuilder(Class<?>... sources) {
super(sources);
Expand All @@ -43,7 +45,14 @@ protected SpringApplication createSpringApplication(ResourceLoader resourceLoade

public GrailsBuilder enableMicronaut() {
if (ClassUtils.isPresent("io.micronaut.spring.context.MicronautApplicationContext", getClass().getClassLoader())) {
this.micronautContext = new MicronautApplicationContext();
try {
Class<?> clazz = getClass().getClassLoader().loadClass("io.micronaut.spring.context.MicronautApplicationContext");
this.micronautContext = (ConfigurableApplicationContext) ReflectionUtils.accessibleConstructor(clazz).newInstance();
}
catch (Exception e) {
throw new IllegalStateException(
"Can't enable Micronaut as the parent application context of Grails", e);
}
}
else {
throw new IllegalStateException(
Expand Down

0 comments on commit 3eba708

Please sign in to comment.