在Elastic Beanstalk上将Grails 3 App部署到Tomcat 8

时间:2017-04-08 20:32:55

标签: java tomcat grails

我正在尝试将Grails 3应用程序部署到Elastic Beanstalk上的Tomcat 8实例,我尝试了一些我在Google和Stack Exchange上发现的内容,包括更改“org.springframework.boot:spring” -boot-starter-tomcat“依赖从”编译“到”提供“,这是行不通的。 Elastic Beanstalk将接受war文件,但只显示一个空白页面。

我打开了Grails生成的war文件,发现在WEB-INF下的基目录或web.xml文件中没有index.jsp文件。这两个都存在于我使用Maven web-app原型制作的简单war文件中,它有效,所以我有两个问题:

1)是否还有其他人从最新版本的Grails到Tomcat 8部署了应用程序?特别是在Elastic Beanstalk上,特别是最近?我从谷歌搜索中找到的大多数答案都是旧的,所以我想也许新版本的内容已经发生了变化。

2)在打开WAR文件并加载它时,看到Tomcat 8进行的过程的最佳参考是什么?我想如果我能深入研究这个过程,我可以找出丢失的部分在哪里。

1 个答案:

答案 0 :(得分:0)

@John Stanford,我发现同样的问题我的grails版本是3.2.3

我在本地测试了部署到我的tomcat8,发现我的数据源配置导致了这个问题,我的grails app只是虚拟app,不需要数据库连接,

log /var/lib/tomcat8/logs/catalina.2017-xx-xx.log显示如下

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsCacheFilter': Cannot create inner bean '(inner bean)#7cbf54fc' of type [grails.plugin.cache.web.filter.simple.MemoryPageFragmentCachingFilter] while setting bean property 'filter'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '(inner bean)#7cbf54fc': Unsatisfied dependency expressed through method 'setUrlMappingsHandlerMapping' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'urlMappingsHandlerMapping': Unsatisfied dependency expressed through method 'setWebRequestInterceptors' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'openSessionInViewInterceptor': Cannot resolve reference to bean 'hibernateDatastore' while setting bean property 'hibernateDatastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:313)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1486)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1231)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)

所以我注释掉了application.yml

的production.dataSource.url
environments:
    development:
        dataSource:
            dbCreate: create-drop
            url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
    test:
        dataSource:
            dbCreate: update
            url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
    production:
        grails:
            serverURL: http://xxx-evn-yyy-zzzz-aws-zone-2.elasticbeanstalk.com
        dataSource:
            dbCreate: none
            #url: jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
            properties:
                jmxEnabled: true
                initialSize: 5
                maxActive: 50
                minIdle: 5
                maxIdle: 25
                maxWait: 10000

最后部署到AWS Beanstalk并且它可以工作!