When running test-app in grails 3.0, or run-app, grails runs its own version of the embedded Tomcat server. I was able to conclude this from the following link: https://rosh
In Grails 3, you do it like this: SampleTomcatJndiApplication
Typically, in Grails web applications, this is in /grails-app/init/Application.groovy
(In my case, I commented out the jndiDataSource()
part and just used postProcessContext()
.)
Source: Graeme Rocher
The solution to this issue is addressed in two steps. First, I had to use the child approach to setting the right context, found in this question. Setting the right context in embedded Tomcat
As imagined, The only change I then had to make was to the getTomcatEmbeddedServletContainer method. I have edited the original to look like this:
@Override
protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {
tomcat.enableNaming();
TomcatEmbeddedServletContainer container =
super.getTomcatEmbeddedServletContainer(tomcat);
for (Container child: container.getTomcat().getHost().findChildren()) {
if (child instanceof Context) {
ClassLoader contextClassLoader =((Context)child).getLoader().getClassLoader();
Thread.currentThread().setContextClassLoader(contextClassLoader);
break;
}
}
return container;
}
Next, I had to edit the gradle build file, to include the dbcp BasicDataSource Dependency. My gradle build file now contains:
dependencies {
// Embedded tomcat dependencies
compile "org.apache.tomcat:tomcat-dbcp:9.0.0.M1"
}