如何在broadleaf中覆盖CustomerStateRequestProcessor

时间:2013-06-24 15:41:17

标签: broadleaf-commerce

如何在broadleaf中使用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 方法。

由于

1 个答案:

答案 0 :(得分:2)

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

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

public class MyCustomerStateRequestProcessor extends
    CustomerStateRequestProcessor {

    ...

 }

然后在任何applicationContext.xml文件中(除了servlet文件)之外添加:

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

请注意,此模式与覆盖任何Broadleaf定义的bean相同。