Java 重写hybris Commoni18n服务roundCurrency方法
尝试使用Java 重写hybris Commoni18n服务roundCurrency方法,java,spring,dependency-injection,hybris,Java,Spring,Dependency Injection,Hybris,尝试使用Alias覆盖springbean 我想超越roundCurrencycommoni18n服务的method OOTB定义 <alias alias="commonI18NService" name="defaultCommonI18NService"/> <bean id="defaultCommonI18NService" class="de.hybris.platform.servicelayer.i18n.impl.DefaultCommonI18NServic
Alias
覆盖springbean
我想超越roundCurrency
commoni18n服务的method
OOTB定义
<alias alias="commonI18NService" name="defaultCommonI18NService"/>
<bean id="defaultCommonI18NService" class="de.hybris.platform.servicelayer.i18n.impl.DefaultCommonI18NService" parent="abstractBusinessService">
<property name="languageDao" ref="languageDao"/>
<property name="currencyDao" ref="currencyDao"/>
<property name="countryDao" ref="countryDao"/>
<property name="regionDao" ref="regionDao"/>
<property name="conversionStrategy" ref="conversionStrategy"/>
</bean>
注入自定义bean:-
<alias alias="commonI18NService" name="defaultCustomCommonI18NService"/>
<bean id="defaultCustomCommonI18NService" class="com.extended.service.impl.DefaultCustomCommonI18NService" parent="defaultCommonI18NService"/>
但它在服务器启动时抛出异常
INFO [localhost-startStop-1] [HybrisContextFactory] Loading <<application>> spring config <master> from extension (saporderexchangeb2b) located in (saporderexchangeb2b-spring.xml) took: (121.4 ms)
WARN [localhost-startStop-1] [CloseAwareApplicationContext] Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'listMergeBeanPostProcessor': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commercePlaceOrderMethodHooksListMergeDirective' defined in class path resource [b2bapprovalprocess-spring.xml]: Cannot resolve reference to bean 'b2bApprovalBusinessProcessCreationPlaceOrderMethodHook' while setting bean property 'add'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'b2bApprovalBusinessProcessCreationPlaceOrderMethodHook' defined in class path resource [b2bapprovalprocess-spring.xml]: Cannot resolve reference to bean 'defaultB2BCreateOrderFromCartStrategy' while setting bean property 'businessProcessCreationStrategy'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultB2BCreateOrderFromCartStrategy' defined in class path resource [b2bapprovalprocess-spring.xml]: Cannot resolve reference to bean 'cloneAbstractOrderStrategy' while setting bean property 'cloneAbstractOrderStrategy'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultCloneAbstractOrderStrategy' defined in class path resource [order-spring.xml]: Cannot resolve reference to bean 'typeService' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultTypeService' defined in class path resource [servicelayer-spring.xml]: Cannot resolve reference to bean 'converterRegistry' while setting bean property 'converterRegistry'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'defaultConverterRegistry' defined in class path resource [servicelayer-spring.xml]: Unsatisfied dependency expressed through bean property 'commonI18NService': : No qualifying bean of type [de.hybris.platform.servicelayer.i18n.CommonI18NService] is defined: expected single matching bean but found 2: defaultCommonI18NService,defaultcustomCommonI18NService; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [de.hybris.platform.servicelayer.i18n.CommonI18NService] is defined: expected single matching bean but found 2: defaultCommonI18NService,defaultcustomCommonI18NService
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
INFO[localhost-startStop-1][HybrisContextFactory]从位于(saporderexchangeb2b-spring.xml)的扩展(saporderexchangeb2b)加载spring配置需要:(121.4毫秒)
上下文初始化过程中遇到警告[localhost-startStop-1][CloseawReapplicationContext]异常-取消刷新尝试
org.springframework.beans.factory.BeanCreationException:创建名为“listMergeBeanPostProcessor”的bean时出错:调用init方法失败;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“commercePlaceOrderMethodHooksListMergeDirective”的bean时出错,该名称在类路径资源[B2BAProvalProcess spring.xml]中定义:设置bean属性“add”时无法解析对bean“B2BAProvalBusinessProcessCreationPlaceOrderMethodHook”的引用;嵌套异常为org.springframework.beans.factory.beancreatitionException:创建名为“B2BAProvalBusinessProcessCreationPlaceOrderMethodHook”的bean时出错,该bean在类路径资源[B2BAProvalProcess spring.xml]中定义:设置bean属性“businessProcessCreationStrategy”时无法解析对bean“defaultB2BCreateOrderFromCartStrategy”的引用;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“defaultB2BCreateOrderFromCartStrategy”的bean时出错,该bean在类路径资源[b2bapprovalprocess spring.xml]中定义:设置bean属性“cloneAbstractOrderStrategy”时无法解析对bean“cloneAbstractOrderStrategy”的引用;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“defaultCloneAbstractOrderStrategy”的bean时出错,该bean在类路径资源[order spring.xml]中定义:设置构造函数参数时无法解析对bean“typeService”的引用;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“defaultTypeService”的bean时出错,该名称在类路径资源[servicelayer spring.xml]中定义:设置bean属性“converterRegistry”时无法解析对bean“converterRegistry”的引用;嵌套异常为org.springframework.beans.factory.UnsatifiedDependencyException:创建名为“defaultConverterRegistry”的bean时出错,该名称在类路径资源[servicelayer spring.xml]中定义:通过bean属性“commonI18NService”表示的未满足的依赖项:没有类型的限定bean已定义[de.hybris.platform.servicelayer.i18n.CommonI18NService]:预期为单个匹配bean,但找到2:defaultCommonI18NService,defaultcustomCommonI18NService;嵌套异常为org.springframework.beans.factory.NonuiquebeandDefinitionException:没有类型为[de.hybris.platform.servicelayer.i18n.CommonI18NService]的合格bean已定义:应为单个匹配bean,但找到2:DefaultCommonI18N服务,DefaultCustomCommonI18N服务
在org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
发生这种情况是因为defaultConverterRegistry
的自动布线策略是byType
:
<bean id="defaultConverterRegistry" ... autowire="byType" >
您如何发现问题是由defaultConverterRegistry
引起的?我无法查看该类的源代码。假设“defaultConverterRegistry”具有公共I18N服务,如@Autowiredit在此处声明的:…\hybris\bin\platform\ext\core\resources\servicelayer-spring.xml,并且它存在于您提供的堆栈跟踪中,如果您想查看e DefaultModelConverterRegistry.class的源您需要使用java反编译器。我没有找到任何与DefaultModelConverterRegistry
相关的stacktrace,我也尝试使用反编译器检查DefaultModelConverterRegistry
的源代码,但没有运气。我假设这个类有自动连接的Commoni18n服务
,它是造成问题的原因。
<bean id="defaultConverterRegistry" ... autowire="byType" >
<bean id="defaultCustomCommonI18NService" class="com.extended.service.impl.DefaultCustomCommonI18NService" parent="defaultCommonI18NService" primary="true" />