在 Grails 2.0.3 上,我安装了 Spring Security Core 并按照教程创建了 User、UserRole 和 Role 对象:http: //blog.springsource.org/2010/08/11/simplified-spring-security-with-grails /
一切都很好,直到我决定添加第二个数据源以准备访问来自不同数据库的对象。DataSource.groovy 看起来像这样:
test {
dataSource_product {
dbCreate = "update"
url = "jdbc:mysql://localhost/products"
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
username = "blah"
password = "blah"
loggingSql = true
dialect = 'org.hibernate.dialect.MySQL5InnoDBDialect'
}
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost/core"
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
username = "blah"
password = "blah"
loggingSql = true
dialect = 'org.hibernate.dialect.MySQL5InnoDBDialect'
}
}
现在我无法登录 - 即使我所做的只是添加 datasource_product。如果我将此注释掉并重新创建用户(在 Bootstrap.groovy 中),那么我可以再次登录。Bootstrap.groovy 包含:
def init =
{ servletContext ->
// Add in roles
Role.withTransaction {
def adminRole = Role.findByAuthority ( Role.ROLE_ADMIN ) ?: new Role ( authority: Role.ROLE_ADMIN ).save ( failOnError: true )
def adminUser = User.findByUsername ( 'admin' ) ?: new User (
username: 'blah',
password: 'blah',
enabled: true ).save ( failOnError: true )
if ( !adminUser.authorities.contains ( adminRole ) ) UserRole.create ( adminUser, adminRole )
}
有任何想法吗?