1

如何在阔叶树中覆盖 CustomerStateRequestProcessor#resolveAuthenticatedCustomer 函数?

我试过这个: -

@Component("blCustomerStateRequestProcessor")
public class MyCustomerStateRequestProcessor extends
        CustomerStateRequestProcessor {

    @Resource(name = "blCustomerService")
    protected CustomerService customerService;

    @Override
    public Customer resolveAuthenticatedCustomer(Authentication authentication) {
        if (authentication instanceof OpenIDAuthenticationToken) {
            OpenIDAuthenticationToken openIDAuthenticationToken = (OpenIDAuthenticationToken) authentication;
            if (openIDAuthenticationToken.isAuthenticated()) {
                return (Customer) openIDAuthenticationToken.getPrincipal();
            } else {
                return null;
            }
        } else {
            return super.resolveAuthenticatedCustomer(authentication);
        }
    }

}

添加了上下文组件扫描:-

<context:component-scan base-package="org.broadleafcommerce.common.web.security,com.mycompany.web.request.processor" />

这导致: -

 org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'blCustomerStateRequestProcessor' for bean class [org.broadleafcommerce.profile.web.core.security.CustomerStateRequestProcessor] conflicts with existing, non-compatible bean definition of same name and class [com.mycompany.web.request.processor.MyCustomerStateRequestProcessor]

我正在尝试覆盖OpenIdAuthenticationToken的 resolveAuthenticatedCustomer方法。

谢谢

4

1 回答 1

2

与其使用组件扫描来重新定义 bean,不如删除该注释并通过 XML 来完成。

因此,您的类定义将更改为:

public class MyCustomerStateRequestProcessor extends
    CustomerStateRequestProcessor {

    ...

 }

然后在您的任何 applicationContext.xml 文件(servlet 文件除外)中添加以下内容:

<bean id="blCustomerStateRequestProcessor" class="com.yourcompany.site.web.MyCustomerStateRequestProcessor" />

请注意,此模式对于覆盖任何 Broadleaf 定义的 bean 都是相同的。

于 2013-06-24T20:53:55.237 回答