各位Maven,你好,我想知道为什么我的案子不能正常运作。
情况:
有一个名为abstractcheckoutstepvalidator的类,下面是它的xml配置:
<bean id="abstractCheckoutStepValidator" class="...checkout.steps.validation.AbstractCheckoutStepValidator" abstract="true">
<property name="checkoutFlowFacade" ref="checkoutFlowFacade"/>
<property name="checkoutFacade" ref="checkoutFacade"/>
</bean>
和代码:
public abstract class AbstractCheckoutStepValidator implements CheckoutStepValidator
{
private CheckoutFacade checkoutFacade;
private CheckoutFlowFacade checkoutFlowFacade;
@Override
public abstract ValidationResults validateOnEnter(final RedirectAttributes redirectAttributes);
@Override
public ValidationResults validateOnExit()
{
return ValidationResults.SUCCESS;
}
public CheckoutFacade getCheckoutFacade()
{
return checkoutFacade;
}
@Required
public void setCheckoutFacade(final CheckoutFacade checkoutFacade)
{
this.checkoutFacade = checkoutFacade;
}
public CheckoutFlowFacade getCheckoutFlowFacade()
{
return checkoutFlowFacade;
}
@Required
public void setCheckoutFlowFacade(final CheckoutFlowFacade checkoutFlowFacade)
{
this.checkoutFlowFacade = checkoutFlowFacade;
}
}
这里是defaultmultistepcheckoutstepvalidator类,它扩展abstractcheckoutstepvalidator并重写它的getter
public class DefaultMultiStepCheckoutStepValidator extends AbstractCheckoutStepValidator {
private static final Logger LOGGER = Logger.getLogger(DefaultMultiStepCheckoutStepValidator.class);
@Resource(name = "companyCheckoutFacade")
private CompanyCheckoutFacade companyCheckoutFacade;
// omitted code
@Override
public CompanyCheckoutFacade getCheckoutFacade() {
return companyCheckoutFacade;
}
}
此类的xml配置:
<bean id="defaultMultiStepCheckoutValidator" class="...checkout.steps.validation.impl.DefaultMultiStepCheckoutStepValidator" parent="abstractCheckoutStepValidator" />
从技术Angular 看应该没问题,如果getter返回父类,那么我可以使用它的一个子类,在我的例子中是companycheckoutfacade扩展checkoutfacade我有一个类似的例子,比如:
@Override
protected CompanyCartFacade getCartFacade() {
return (CompanyCartFacade) super.getCartFacade();
}
但在这里,我确信返回的bean可以被浇铸到这个子类,这就是为什么我从父类调用getter,这个getter在父类或子类中都可以正常工作)
同样在代码中,我通过注解注入依赖项,并且这个字段与父类中的checkoutfacade字段无关。。。如果使用上述代码启动服务器,则会出现以下错误:
Error creating bean with name 'defaultMultiStepCheckoutValidator' defined in ServletContext resource [/WEB-INF/config/multi-step-checkout-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '...order.impl.DefaultCheckoutFacade' to required type '...facades.order.CompanyCheckoutFacade' for property 'checkoutFacade'; nested exception is java.lang.IllegalStateException: Cannot convert value of type '...order.impl.DefaultCheckoutFacade' to required type '...facades.order.CompanyCheckoutFacade' for property 'checkoutFacade': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:342) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:113) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.lambda$resolveManagedMap$1(BeanDefinitionValueResolver.java:453) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684) ~[?:?]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedMap(BeanDefinitionValueResolver.java:451) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:181) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1697) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1442) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:330) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:113) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.lambda$resolveManagedMap$1(BeanDefinitionValueResolver.java:453) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684) ~[?:?]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedMap(BeanDefinitionValueResolver.java:451) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:181) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1697) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1442) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeanByName(AbstractAutowireCapableBeanFactory.java:453) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:527) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:497) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:650) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:239) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:318) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
... 27 more
问题是:
从上面的错误中,我真的不明白为什么spring试图将类型为“…order.impl.defaultcheckoutfacade”的属性值转换为属性“checkoutfacade”所需的类型“…facades.order.companycheckoutfacade”。我的getter中没有使用checkoutfacade属性。defaultcheckoutfacade是checkoutfacade接口的默认实现,我确信xml配置中的checkoutfacade ref引用了正确的实现,如下所示:
<alias name="defaultCheckoutFacade" alias="checkoutFacade"/>
<bean id="defaultCheckoutFacade" class="...order.impl.DefaultCheckoutFacade">
// properties are omitted
</bean>
我是说getter应该返回不同的实现,就是这样。为了消除这个错误,我只需要重命名getter,而不重写父类中的getter,但我不明白为什么重写getter的方法不起作用?
谢谢你花时间/回答问题。
暂无答案!
目前还没有任何答案,快来回答吧!