Grails 2.3.2不会调用ForkedTomcatCustomizer

时间:2013-11-08 11:41:26

标签: grails groovy ajp

我将我的grails应用程序从2.2.4升级到grails 2.3.2。我以前使用_Events.groovy eventConfigureTomcat()闭包从apache httpd mod_jk建立一个ajp连接。升级时,我发现不再支持此功能,但推荐的方法是实现org.grails.plugins.tomcat.ForkedTomcatCustomizer customize()方法,我可以在其中建立ajp连接器。 See grails docs and search on ForkedTomcatConnector

我的问题是永远不会调用代码。

我在/ src / groovy目录中实现了ForkedTomcatCustomizer。这是代码:

package org.grails.plugins.tomcat

import grails.util.Environment
import org.apache.catalina.connector.Connector
import org.apache.catalina.startup.Tomcat

/**
 * Forked tomcat customizer adds ajp connect to support apache ajp in dev env
 * from within IDE
 */
class ForkedTomcatCustomizer
{
    void customize(Tomcat tomcat)
    {
        println("In the ForkedTomcatCustomizer.customize() method")
        if (Environment.getCurrent() == Environment.DEVELOPMENT)
        {
            def ajpConnector = new Connector("org.apache.coyote.ajp.AjpProtocol")
            ajpConnector.port = 8009
            ajpConnector.protocol = "AJP/1.3"
            ajpConnector.redirectPort = 8443
            ajpConnector.enableLookups = false
            ajpConnector.setProperty("redirectPort", "8443")
            ajpConnector.setProperty("protocol", "AJP/1.3")
            ajpConnector.setProperty("enableLookups", "false")
            tomcat.service.addConnector ajpConnector
            println "Added ajp connector"
        }
    }
}

有人见过/解决过这个问题吗?

1 个答案:

答案 0 :(得分:0)

这似乎是一个错误。

请参阅以下TomcatDevelopmentRunner中的代码段... forkedClassLoader成员在调用invokeCustomizer时仍然为空(来自超类构造函数)。正如您所见,NPE被吞下,过程无声地失败......

    private void invokeCustomizer(Tomcat tomcat) {
        Class cls = null
        try {
            cls = forkedClassLoader.loadClass("org.grails.plugins.tomcat.ForkedTomcatCustomizer")
        } catch (Throwable e) {
            // ignore
        }
        ...