扩展 InlineExplodedTomcatServer
package myapp
import org.grails.plugins.tomcat.InlineExplodedTomcatServer
import org.grails.plugins.tomcat.TomcatLoader
import grails.util.GrailsNameUtils
import org.apache.catalina.connector.Connector
import org.apache.catalina.startup.Tomcat
import org.apache.coyote.http11.Http11NioProtocol
import org.codehaus.groovy.grails.lifecycle.ShutdownOperations
import org.codehaus.groovy.grails.plugins.PluginManagerHolder
import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
import static grails.build.logging.GrailsConsole.instance as CONSOLE
import org.apache.tomcat.util.scan.StandardJarScanner
import org.springframework.util.ReflectionUtils
class MyappInlineExplodedTomcatServer extends InlineExplodedTomcatServer {
MyappInlineExplodedTomcatServer(String basedir, String webXml, String contextPath, ClassLoader classLoader) {
super(basedir, webXml, contextPath, classLoader)
context.setSessionCookieDomain(System.getProperty('mydomain.com'))
context.setSessionCookiePath('/mypath')
}
}
扩展tomcat服务器工厂
package myapp
import grails.web.container.EmbeddableServer
import org.grails.plugins.tomcat.TomcatServerFactory
class MyappServerFactory extends TomcatServerFactory {
EmbeddableServer createInline(String basedir, String webXml, String contextPath, ClassLoader classLoader) {
new MyappInlineExplodedTomcatServer(basedir, webXml, contextPath, classLoader)
}
}
在 events.groovy 中设置服务器工厂
eventRunAppStart = {
System.setProperty 'grails.server.factory','myapp.MyappServerFactory'
}
}
显然,此配置仅在使用 grails "run-app" 运行时应用,而不是在部署在 tomcat 或其他服务器上时应用。在 tomcat 上,您必须在 tomcat 配置文件中配置它