Java 使用父属性重写Springbean

Java 使用父属性重写Springbean,java,spring,spring-mvc,grails,groovy,Java,Spring,Spring Mvc,Grails,Groovy,我想知道是否有可能重写bean定义,但按原样使用父bean的属性 我正在使用Grails2.5.0和SpringSecurityCore2.0-RC4。在插件的描述符文件(即SpringSecurityCoreGrailsPlugin)中,beanauthenticationProcessingFilter注册为: authenticationProcessingFilter(RequestHolderAuthenticationFilter) { authenticationManag

我想知道是否有可能重写bean定义,但按原样使用父bean的属性

我正在使用Grails2.5.0和SpringSecurityCore2.0-RC4。在插件的描述符文件(即
SpringSecurityCoreGrailsPlugin
)中,bean
authenticationProcessingFilter
注册为:

authenticationProcessingFilter(RequestHolderAuthenticationFilter) {
    authenticationManager = ref('authenticationManager')
    sessionAuthenticationStrategy = ref('sessionAuthenticationStrategy')
    authenticationSuccessHandler = ref('authenticationSuccessHandler')
    authenticationFailureHandler = ref('authenticationFailureHandler')
    rememberMeServices = ref('rememberMeServices')
    authenticationDetailsSource = ref('authenticationDetailsSource')
    requiresAuthenticationRequestMatcher = ref('filterProcessUrlRequestMatcher')
    usernameParameter = conf.apf.usernameParameter // j_username
    passwordParameter = conf.apf.passwordParameter // j_password
    postOnly = conf.apf.postOnly // true
}
现在,我想使用我自己的
authenticationProcessingFilter
,它在尝试登录之前执行其他操作,因此我定义了一个类:

class CustomAuthenticationFilter extends RequestHolderAuthenticationFilter {

    @Override
    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
        println "Overridden bean"
        return super.attemptAuthentication(request, response)
    }
}
(我只是扩展父bean类,现在添加了一个print语句)

现在,我尝试使用这个类来替换Spring插件定义的类。所以我在
参考资料中写了这样的东西

beans = {
    authenticationProcessingFilter(CustomAuthenticationFilter)
}
当我启动Grails应用程序时,它开始抱怨必须指定
authenticationManager
。所以我搜索了这个问题,找到了一些文章,但是没有帮助。(第条和第条)

所以我尝试了类似的方法来使用
parent
属性:

beans = {
    authenticationProcessingFilter(CustomAuthenticationFilter) { bean ->
        bean.parent = ref('authenticationProcessingFilter')
    }
}
但是上面的代码也不起作用。我认为当bean是用XML定义的时候,通过
value=“parent”
属性是可能的,但我不能用Java的方式来完成

我唯一的选择是重新定义我的
资源中的所有属性。groovy
类似:

authenticationProcessingFilter(CustomAuthenticationFilter) {
    authenticationManager = ref('authenticationManager')
    sessionAuthenticationStrategy = ref('sessionAuthenticationStrategy')
    authenticationSuccessHandler = ref('authenticationSuccessHandler')
    authenticationFailureHandler = ref('authenticationFailureHandler')
    // and other properties like so
}
还是有更干净的方法