Grails 2.5.5を使用しています。Grailsでデータベーススキーマを生成する前にスクリプトを実行するには?
class Organization {
String uid = String.uuid()
...
}
問題がある:
String.metaClass.static.uuid = { ->
java.util.UUID.randomUUID().toString()
}
そして、私のドメインクラスで、私はUIDフィールドを初期化するために、そのメソッドを使用します:文字列のUUIDを生成するために私のブートストラップでは、私は、静的メソッドを登録しました私はGrailsアプリケーションを実行し、データベーススキーマを生成します。これはブートストラップを実行する前に起こるようです。世代によってドメインクラスのインスタンスが作成されますが、String.uuid()はまだ登録されていないため、MissingMethodExceptionが発生します。
データベーススキーマ生成前に実行されるスクリプトを作成して、すべてのメソッドをスキーマ生成時に使用できるように登録するにはどうすればよいですか?
はFYI:フルスタックトレース
2016-11-08 17:11:23,638 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener - Error initializing the application: Error creating b
ean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreatio
nException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'se
ssionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invoc
ation of init method failed; nested exception is org.hibernate.MappingException: Could not get constructor for org.codehaus.groovy.grails.orm.hib
ernate.persister.entity.GroovyAwareSingleTableEntityPersister
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.
beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while
setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with nam
e 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not get constructor for org.codeh
aus.groovy.grails.orm.hibernate.persister.entity.GroovyAwareSingleTableEntityPersister
Line | Method
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while sett
ing bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 's
essionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not get constructor for org.codehaus.
groovy.grails.orm.hibernate.persister.entity.GroovyAwareSingleTableEntityPersister
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibern
ate.MappingException: Could not get constructor for org.codehaus.groovy.grails.orm.hibernate.persister.entity.GroovyAwareSingleTableEntityPersist
er
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by MappingException: Could not get constructor for org.codehaus.groovy.grails.orm.hibernate.persister.entity.GroovyAwareSingleTableEntityP
ersister
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by InstantiationException: could not instantiate test object : com.cabolabs.ehrserver.query.Query
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by InvocationTargetException: null
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by MissingMethodException: No signature of method: static java.lang.String.uuid() is applicable for argument types:() values: []
Possible solutions: wait(), trim(), dump(), find(), wait(long), is(java.lang.Object)
->> 28 | <init> in com.cabolabs.ehrserver.query.Query
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 262 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run . . . in java.lang.Thread
私の場合、loadBefore = ['domain']のようなものでしょうか?ドキュメントは、loadBeforeに可能なすべての値を表示していないようです。 –
実際には、データベース移行プラグインの前にプラグインがロードされるように、 'loadBefore = ['database-migration']'が必要です。プラグイン名は100%確信しているわけではありませんが、ソースをすばやく見れば上記が正しいと思います。 –