Adding JNDI to embedded Tomcat server in Grails 3

前端 未结 2 1320
甜味超标
甜味超标 2021-01-07 12:23

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

相关标签:
2条回答
  • 2021-01-07 12:59

    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

    0 讨论(0)
  • 2021-01-07 13:01

    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"
    }
    
    0 讨论(0)
提交回复
热议问题