我正在使用Grails 2.2.2,audit-trail插件2.0.3和spring-security-core 1.2.7.3

当我将注释放在类上并使用浏览器(通过Controller / gsp)插入记录时,一切正常。

@gorm.AuditStamp 
class Note { 
   String name 
} 

但是,当我在Bootstrap中插入记录时
new Note(name:'Testing').save() 

启动时出现错误
ERROR property.BasicPropertyAccessor  - IllegalArgumentException in class: test.Note, setter method of property: createdBy 
ERROR property.BasicPropertyAccessor  - expected type: java.lang.Long, actual value: java.lang.Integer 
ERROR context.GrailsContextLoader  - Error initializing the application: IllegalArgumentException occurred while calling setter of test.Note.createdBy; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of test.Note.createdBy 

有没有一种方法可以使Bootstrap期间的审核跟踪工作正常进行?我只是想在从Bootstrap插入时放置默认值,而在使用浏览器屏幕插入时登录的用户。我使用以下更改,但仍然没有运气:
static mapping = { 
    createdBy (defaultValue: Long.valueOf( 1l )) 
    editedBy (defaultValue: Long.valueOf( 1l )) 
} 
static constraints = { 
    createdBy nullable:true 
    editedBy nullable:true 
} 

我仍然遇到相同的Long / Integer错误

编辑:

这是与该pkugin相关的Config.groovy的内容
grails { 
    plugin{ 
        audittrail{ 
            createdBy.field = "createdBy" 
            editedBy.field = "editedBy" 
            createdDate.field = "createdDate" 
            editedDate.field = "editedDate" 
        } 
    } 
} 

请您参考如下方法:

您可以使用SpringSecurityUtils.doWithAuth伪造安全上下文

import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils 
 
// set up a default user, if one doesn't already exist 
def defaultUser = User.findByUsername('default') ?: new User(username:'default').save() 
 
// run the following code as if that user were logged in 
SpringSecurityUtils.doWithAuth('default') { 
  new Note(name:'Testing').save() 
} 


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!