关于heroku的Grails 2.3.4 - BeanCreationException

时间:2014-05-21 06:58:17

标签: grails heroku grails-2.0

只是想在heroku上部署我的grails 2.3.4应用程序。但是,该应用程序无法启动。这是我的应用程序的日志:

2014-05-21T06:41:49.110139+00:00 app[web.1]: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/TestApp/ContactController$_sendEmail_closure4
2014-05-21T06:41:49.110141+00:00 app[web.1]:    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
2014-05-21T06:41:49.110142+00:00 app[web.1]:    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
2014-05-21T06:41:49.110144+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
2014-05-21T06:41:49.110146+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
2014-05-21T06:41:49.110148+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:679)
2014-05-21T06:41:49.110150+00:00 app[web.1]: Caused by: java.lang.NoClassDefFoundError: com/TestApp/ContactController$_sendEmail_closure4
2014-05-21T06:41:49.110151+00:00 app[web.1]:    at java.lang.Class.forName(Class.java:266)
2014-05-21T06:41:49.110153+00:00 app[web.1]:    ... 5 more
2014-05-21T06:41:49.110154+00:00 app[web.1]: Caused by: java.lang.ClassNotFoundException: com.TestApp.ContactController$_sendEmail_closure4
2014-05-21T06:41:49.110156+00:00 app[web.1]:    ... 6 more
2014-05-21T06:41:49.113516+00:00 app[web.1]: context.GrailsContextLoader Error initializing the application: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/TestApp/ContactController$_sendEmail_closure4
2014-05-21T06:41:49.113519+00:00 app[web.1]: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/TestApp/ContactController$_sendEmail_closure4
2014-05-21T06:41:49.113521+00:00 app[web.1]:    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
2014-05-21T06:41:49.113523+00:00 app[web.1]:    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
2014-05-21T06:41:49.113524+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
2014-05-21T06:41:49.113526+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
2014-05-21T06:41:49.113527+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:679)
2014-05-21T06:41:49.113529+00:00 app[web.1]: Caused by: java.lang.NoClassDefFoundError: com/TestApp/ContactController$_sendEmail_closure4
2014-05-21T06:41:49.113530+00:00 app[web.1]:    at java.lang.Class.forName(Class.java:266)
2014-05-21T06:41:49.113532+00:00 app[web.1]:    ... 5 more
2014-05-21T06:41:49.113533+00:00 app[web.1]: Caused by: java.lang.ClassNotFoundException: com.TestApp.ContactController$_sendEmail_closure4
2014-05-21T06:41:49.113535+00:00 app[web.1]:    ... 6 more
2014-05-21T06:41:49.114836+00:00 app[web.1]: context.GrailsContextLoader Error initializing Grails: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/TestApp/ContactController$_sendEmail_closure4
2014-05-21T06:41:49.114840+00:00 app[web.1]: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/TestApp/ContactController$_sendEmail_closure4
2014-05-21T06:41:49.114842+00:00 app[web.1]:    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
2014-05-21T06:41:49.114844+00:00 app[web.1]:    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
2014-05-21T06:41:49.114845+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
2014-05-21T06:41:49.114847+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
2014-05-21T06:41:49.114850+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:679)
2014-05-21T06:41:49.114857+00:00 app[web.1]: Caused by: java.lang.NoClassDefFoundError: com/TestApp/ContactController$_sendEmail_closure4
2014-05-21T06:41:49.114859+00:00 app[web.1]:    at java.lang.Class.forName(Class.java:266)
2014-05-21T06:41:49.114860+00:00 app[web.1]:    ... 5 more
2014-05-21T06:41:49.114862+00:00 app[web.1]: Caused by: java.lang.ClassNotFoundException: com.TestApp.ContactController$_sendEmail_closure4
2014-05-21T06:41:49.114863+00:00 app[web.1]:    ... 6 more
2014-05-21T06:41:49.115283+00:00 app[web.1]: May 21, 2014 6:41:49 AM org.apache.catalina.core.StandardContext listenerStart
2014-05-21T06:41:49.115286+00:00 app[web.1]: SEVERE: Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
2014-05-21T06:41:49.115289+00:00 app[web.1]: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/TestApp/ContactController$_sendEmail_closure4
2014-05-21T06:41:49.115290+00:00 app[web.1]:    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
2014-05-21T06:41:49.115292+00:00 app[web.1]:    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
2014-05-21T06:41:49.115294+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
2014-05-21T06:41:49.115295+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
2014-05-21T06:41:49.115297+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:679)
2014-05-21T06:41:49.115299+00:00 app[web.1]: Caused by: java.lang.NoClassDefFoundError: com/TestApp/ContactController$_sendEmail_closure4
2014-05-21T06:41:49.115300+00:00 app[web.1]:    at java.lang.Class.forName(Class.java:266)
2014-05-21T06:41:49.115302+00:00 app[web.1]:    ... 5 more
2014-05-21T06:41:49.115303+00:00 app[web.1]: Caused by: java.lang.ClassNotFoundException: com.TestApp.ContactController$_sendEmail_closure4
2014-05-21T06:41:49.115304+00:00 app[web.1]:    ... 6 more
2014-05-21T06:41:49.115495+00:00 app[web.1]: May 21, 2014 6:41:49 AM org.apache.catalina.core.StandardContext startInternal
2014-05-21T06:41:49.115498+00:00 app[web.1]: SEVERE: Error listenerStart
2014-05-21T06:41:49.125446+00:00 app[web.1]: May 21, 2014 6:41:49 AM org.apache.catalina.core.StandardContext startInternal
2014-05-21T06:41:49.125452+00:00 app[web.1]: SEVERE: Context [] startup failed due to previous errors
2014-05-21T06:41:49.129375+00:00 app[web.1]: SEVERE: Context [] failed in [org.apache.catalina.core.StandardContext] lifecycle. Allowing Tomcat to shutdown.
2014-05-21T06:41:49.163675+00:00 app[web.1]: May 21, 2014 6:41:49 AM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
2014-05-21T06:41:49.163682+00:00 app[web.1]: SEVERE: The web application [] registered the JDBC driver [org.h2.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
2014-05-21T06:41:49.163769+00:00 app[web.1]: May 21, 2014 6:41:49 AM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
2014-05-21T06:41:49.163771+00:00 app[web.1]: SEVERE: The web application [] registered the JDBC driver [org.postgresql.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
2014-05-21T06:41:49.183725+00:00 app[web.1]: May 21, 2014 6:41:49 AM org.apache.coyote.AbstractProtocol start
2014-05-21T06:41:49.183733+00:00 app[web.1]: INFO: Starting ProtocolHandler ["http-nio-52650"]
2014-05-21T06:41:50.870008+00:00 heroku[web.1]: State changed from crashed to starting
2014-05-21T06:41:50.869318+00:00 heroku[web.1]: State changed from up to crashed
2014-05-21T06:41:50.853727+00:00 heroku[web.1]: Process exited with status 0

正如您所看到的,第一个例外是我的sendEmail中的ContactController方法:

@Secured(['permitAll'])
@Transactional(readOnly = true)
class ContactController {

    private static final log = LogFactory.getLog(this)

    static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE", notify: "POST"]

    def mailService

    def index(Integer max) {
        params.max = Math.min(max ?: 10, 100)
        respond Contact.list(params), model:[contactInstanceCount: Contact.count()]
    }

    def create() {

        log.info("enter create contacts method")

        respond new Contact(params)
    }

    protected void notFound() {
        request.withFormat {
            form {
                flash.message = message(code: 'default.not.found.message', args: [message(code: 'contactInstance.label', default: 'Contact'), params.id])
                redirect action: "index", method: "GET"
            }
            '*'{ render status: NOT_FOUND }
        }
    }

    public def sendEmail(Contact contactInstance) {

        log.info("call sendEmail method")

        EmailSettings emailAddresses = new EmailSettings()

        if (emailAddresses.list() == null) {
            notFound()
            return
        }


        mailService.sendMail {

            log.info("send email to address list")
            log.info("send emails to: " + EmailSettings.all*.emailAddress)

            from "test@gmail.com"
            to  EmailSettings.all*.emailAddress
            subject "[Customer Notification]  " +  contactInstance.firstName + " " + contactInstance.lastName
            body contactInstance.description

        }

        request.withFormat {
            form {
                flash.message = message(code: 'default.updated.message', args: [message(code: 'Contact.label', default: 'Contact'), contactInstance.id])

                log.info("contactInstance: " + contactInstance.toString())
//              redirect contactInstance
            }
//          '*'{ respond contactInstance, [status: OK] }
        }
    }
}

在开发模式下,我没有得到任何这些例外。任何建议我的ContactController.groovy有什么问题?

感谢您的回答!

1 个答案:

答案 0 :(得分:1)

我试图重现这个问题,但我得到的例外是不同的。尝试以下步骤可能会解决您的问题:

<强> BuildConfig

compile ":mail:1.0.5"

<强>配置

grails {
  mail {
    host = "smtp.gmail.com"
    port = 465
    username = EMAIL_ADDRESS
    password = PASSWORD
    props = ["mail.smtp.auth": "true",
            "mail.smtp.socketFactory.port": "465",
            "mail.smtp.socketFactory.class": "javax.net.ssl.SSLSocketFactory",
            "mail.smtp.socketFactory.fallback": "false"]
  }
}

<强>控制器

def mailService

def index() {
    mailService.sendMail {
        from "test@gmail.com"
        to EmailSettings.all*.emailAddress.collect { it.trim() }
        subject "Test - ${new Date()}"
        body "Body"
    }

    render "OK"
}