2013-12-17 29 views
1

我在一個簡單的應用程序中使用spring安全性。連接到amazon RDS實例時,該應用在本地運行良好。當我上傳我的應用程序彈性魔豆創建一個角色的失敗,在引導:寫入mysql的grails bootstrap錯誤

def init = { servletContext -> 

    println log.name 

    log.debug("hello 1") 
    def adminRole = new Role(authority: 'ROLE_ADMIN') 
    log.debug("hello 2") 
    if (!adminRole.save(flush: true, failOnError: true)) { 
     log.debug("hello 3") 
     adminRole.errors.each { 
      println it 
      log.error(it) 
     } 
    } 

2013-12-17 23:25:33,311 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: groovy.lang.MissingMethodException: No signature of method: com.nrfa.Role.save() is applicable for argument types:() values: [] 
Possible solutions: save(), save(boolean), save(java.util.Map), wait(), last(), any() 
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: com.nrfa.Role.save() is applicable for argument types:() values: [] 
Possible solutions: save(), save(boolean), save(java.util.Map), wait(), last(), any() 
    at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:308) 
    at grails.util.Environment.executeForEnvironment(Environment.java:301) 
    at grails.util.Environment.executeForCurrentEnvironment(Environment.java:277) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:724) 
Caused by: groovy.lang.MissingMethodException: No signature of method: com.nrfa.Role.save() is applicable for argument types:() values: [] 
Possible solutions: save(), save(boolean), save(java.util.Map), wait(), last(), any() 
    at BootStrap$_closure1.doCall(BootStrap.groovy:15) 
    ... 9 more 

如果它是一個數據庫連接的問題 - 它可能是 - 我還以爲錯誤會一直「哎, '連接到數據庫'。不是無法找到Role.save()的非描述性錯誤。

編輯: 全部引導:

import com.nrfa.Role 
import com.nrfa.User 
import com.nrfa.UserRole 

class BootStrap { 
    def springSecurityService 

    def init = { servletContext -> 

     println log.name 

     log.debug("hello 1") 
     def adminRole = new Role(authority: 'ROLE_ADMIN') 
     log.debug("hello 2") 
     if (!adminRole.save(flush: true, failOnError: true)) { 
      log.debug("hello 3") 
      adminRole.errors.each { 
       println it 
       log.error(it) 
      } 
     } 
     log.debug("hello 4") 
     def userRole = new Role(authority: 'ROLE_USER').save(flush: true, failOnError: true) 

     def testUser = new User(username: 'me', password: 'password') 
     testUser.save(flush: true, failOnError: true) 

     UserRole.create testUser, userRole, true 

     assert User.count() == 1 
     assert Role.count() == 2 
     assert UserRole.count() == 1 


    } 

    def destroy = { 
    } 
} 

編輯:包括BuildConfig.Groovy:

dependencies { 
    // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g. 

    //runtime 'mysql:mysql-connector-java:5.1.27' 

    runtime 'org.slf4j:slf4j-api:1.7.5' 
} 

plugins { 
    build ":hibernate:$grailsVersion" 
    runtime ":jquery:1.8.3" 
    runtime ":resources:1.2" 
    runtime ":mysql-connectorj:5.1.22.1" 
    compile ':spring-security-core:2.0-RC2' 


    // Uncomment these (or add new ones) to enable additional resources capabilities 
    //runtime ":zipped-resources:1.0" 
    //runtime ":cached-resources:1.0" 
    //runtime ":yui-minify-resources:0.1.5" 

    build ":tomcat:$grailsVersion" 

    build ":database-migration:1.3.2" 

    compile ':cache:1.0.1' 

//運行 「的:mysql-的ConnectorJ:5.1.22.1」 }

+0

我開始相信這是創建war文件的問題,並且mysql連接器沒有被拾取。最初它是一個依賴項(沒有工作)。我將其更改爲插件(仍然無法使用)。在彈性beanstalk中安裝tomcat7不會附帶一個mysql jar文件。 – spock99

+0

你可以分享完整的BootStrap.groovy文件嗎? –

+0

完全引導添加。 – spock99

回答

0

該錯誤通常表明hibernate插件沒有被安裝或工作。你能看到遠程服務器上的擴展戰爭嗎?我不熟悉豆杆本身的運作,所以也許有些東西在那裏發生衝突。

+0

我列出了我的BuildConfig.groovy。 war文件確實有一些hibernate jar - hibernate-jpa-2.0-api-1.0.1.Final - 但不包括我的IDE中列出的hibernate-core。 – spock99

+0

你運行的是哪個版本的grails?我沒有看到它列出。在grails 2.x中,「hibernate:$ grailsVersion不再被接受,它必須是具體的,以2.3.0爲例,它是hibernate:3.6.10.M6,在2.3.4中它是hibernate:3.6.10.2。 2.2.34是7.0.42 – Robert

0

在依賴項中添加「runtime'mysql:mysql-connector-java:5.1.27'」並將其從插件中刪除?

+0

這就是我原來的問題,問題是amazon aws上的tomcat7安裝不包含mysql連接器的jar文件,所以它從來沒有用這個選項正常運行 – spock99

+0

它絕對在依賴關係中,而不是插件。該jar畢竟不是grails插件。 – Robert