我在测试配置了多个数据源的 Grails 4 时遇到了问题。
领域类
@GrailsCompileStatic
@EqualsAndHashCode(includes = 'authority')
@ToString(includes = 'authority', includeNames = true, includePackage = false)
class Role implements Serializable {
String authority
static constraints = {
authority nullable: false, blank: false, unique: true
}
static mapping = {
datasource ConnectionSource.ALL
}
}
测试班
class RoleSpec extends Specification implements DataTest {
void setupSpec() {
mockDomain Role
}
void "test nothing"() {
expect:
true
}
}
我收到此错误:
Invalid connection [ALL] configured for class [class us.cloudcard.api.Role]
org.grails.datastore.mapping.core.exceptions.ConfigurationException: Invalid connection [ALL] configured for class [class us.cloudcard.api.Role]
at org.grails.datastore.mapping.simple.SimpleMapDatastore$4.getDatastoreForQualifier(SimpleMapDatastore.java:256)
at org.grails.datastore.mapping.simple.SimpleMapDatastore$4.getStaticApi(SimpleMapDatastore.java:226)
at org.grails.datastore.gorm.GormEnhancer.registerEntity(GormEnhancer.groovy:154)
at org.grails.datastore.mapping.simple.SimpleMapDatastore$3.persistentEntityAdded(SimpleMapDatastore.java:218)
at org.grails.datastore.mapping.model.AbstractMappingContext.addPersistentEntities(AbstractMappingContext.java:288)
at grails.testing.gorm.DataTest$Trait$Helper.mockDomains(DataTest.groovy:80)
at grails.testing.gorm.DataTest$Trait$Helper.mockDomain(DataTest.groovy:65)
at grails.testing.gorm.DataTest$Trait$Helper.mockDomain(DataTest.groovy:64)
at us.cloudcard.api.RoleSpec.setupSpec(RoleSpec.groovy:10)
应用程序.yml
environments:
development:
dataSource:
pooled: true
driverClassName: com.mysql.jdbc.Driver
(rest of the dev datasource ...)
test:
dataSource:
dbCreate: update
url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
dataSources:
readReplica:
dbCreate: update
url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
我不知道该去哪里,所以我可以使用您可以提供的任何帮助。
谢谢!