Override hybris commonI18NService roundCurrency method - java

Trying to override spring bean using Alias.
I want to over ride roundCurrency method of commonI18NService
OOTB definition
<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>
Our custom code :-
public class DefaultCustomCommonI18NService extends DefaultCommonI18NService
{
#Override
public double roundCurrency(double value, int digits)
{
// custom logic
return value;
}
}
Inject custom bean :-
<alias alias="commonI18NService" name="defaultCustomCommonI18NService"/>
<bean id="defaultCustomCommonI18NService" class="com.extended.service.impl.DefaultCustomCommonI18NService" parent="defaultCommonI18NService"/>
But it throws exception on server startUP
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]

This is happening because the autowiring strategy of defaultConverterRegistry is byType:
<bean id="defaultConverterRegistry" ... autowire="byType" >
which means Spring found two candidates for commonI18NService bean defaultCommonI18NService and defaultcustomCommonI18NService hence don't know which one to inject.
I propose to make your defaultcustomCommonI18NService a primary bean to be the autowired by using primary="true", see
<bean id="defaultCustomCommonI18NService" class="com.extended.service.impl.DefaultCustomCommonI18NService" parent="defaultCommonI18NService" primary="true" />

Related

ERROR o.s.web.context.ContextLoader - Context initialization failed

I am struck with this error from 2 days. Any help?
ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sessionFilter' defined in file [/usr/local/tomcat/webapps/portal/WEB-INF/classes/META-INF/spring/applicationContext-security.xml]: Unsatisfied dependency expressed through constructor argument with index 1 of type [com.xxx.cloud.common.sessionclient.retrievers.SessionRetrievalStrategy]: : Error creating bean with name 'securityConfig': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xxx/abc/realm_id' is defined: not found in JNDI environment; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfig': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xxx/abc/realm_id' is defined: not found in JNDI environment
Code:
#Resource(mappedName = "xyz/abc/realm_id")
private String assId;
#Bean
public String assId() {
return assId;
}
applicationContext-Security.xml where the bean is defined, but it doesnt pick up
<beans:bean id="xyz/abc/realm_id" class="com.xxxxxxxx.SecurityConfig">
<beans:property name="assId" value="123456789"/>
</beans:bean>
We cannot use tomcat context.xml.

Failed to determine a suitable driver class

when starting the application, see the below error:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blockDataController': Injection of resource dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blockSummaryImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'prodCodeMapper' defined in file [D:\YueNiuProject\StockMarket\yueniu-stock-data\market-data-dao\target\classes\com\yueniu\stock\market\data\mapper\block\ProdCodeMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception;
nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
the connection with a sql database, you must configure datasource in application.properties
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://..
spring.datasource.username=//..
spring.datasource.password=//..
if you dont need to config the datasource, you can use the exclude . like this:
#SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
it would not register the DataSource with default configuration, then passed the issue for throw Exception
sometimes if you bean configuration in same package it won't work. Like the properties loading bean need to be in separate package. Not sure this answer will be accepted or not , for me it worked after moving below code into different package.
#Bean
public PlatformTransactionManager oracleTransactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(oracleEntityManager().getObject());
return transactionManager;
}

Alfresco compatibility with Existing Oracle DB

I have installed Enterprise Version of alfresco and trying to use it with existing Oracle DB schema.
For that I have changed properties in alfresco-global.properties file from PostgreSQL to Oracle.
And I am getting authenticate error while login into alfresco admin.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.beans.factory.config.PropertyPathFactoryBean#48ff4096' defined in class path resource [alfresco/ibatis/ibatis-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialect' defined in class path resource [alfresco/hibernate-context.xml]: Cannot resolve reference to bean '&sessionFactory' while setting bean property 'localSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceCheck' defined in class path resource [alfresco/core-services-context.xml]: Cannot resolve reference to bean '&sessionFactory' while setting bean property 'localSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [alfresco/hibernate-context.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:276)
... 105 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialect' defined in class path resource [alfresco/hibernate-context.xml]: Cannot resolve reference to bean '&sessionFactory' while setting bean property 'localSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceCheck' defined in class path resource [alfresco/core-services-context.xml]: Cannot resolve reference to bean '&sessionFactory' while setting bean property 'localSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [alfresco/hibernate-context.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:334)

Invalid property 'priority' of bean class [org.quartz.CronTrigger]: Bean property 'priority' is not writable or has an invalid setter method

Error in SpringFramework 3.x with Quartz 2.x.x
deploy failed WAR file in Jboss 5.2.0 environment
the error
ERROR [org.springframework.web.context.ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'artifactBatchTrigger' defined in class path resource [applicationContext-quartz.xml]: Invocation of init method failed; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'priority' of bean class [org.quartz.CronTrigger]: Bean property 'priority' is not writable or has an invalid setter method.
Does the parameter type of the setter match the return type of the getter?
the xml file config spring
....
<bean name="artifactBatchTask"
class="it.infocamere.middleware.mccplus.quartz.ArtifactBatchTask">
<property name="batchService" ref="artifactBatchService" />
</bean>
......
I suppose a conflict libraries quart with spring.
thank you
nicola

including hibernate-validator breaks existing hibernate configuration

I am writing a java module in which I have used hibernate validator. The module works fine by itself.
However when it is included as part of a parent project which uses hibernate for standard entity mapping as an ORM, the parent module breaks down by complaining that it is unable to set up the validation factory (and thus fails to setup the session factory).
exception message is "Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable to get the default Bean Validation factory"
-Pulkit
EDIT:
hibernate-validator : 4.3.1.Final
hibernate-core : 3.6.5
Stacktrace :
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'messageSourceServiceTarget' defined in class
path resource [applicationContext-service.xml]: Cannot resolve
reference to bean 'mutableResourceBundleMessageSource' while setting
bean property 'activeMessageSource'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'mutableResourceBundleMessageSource' defined
in class path resource [applicationContext-service.xml]:
Initialization of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor#0'
defined in class path resource [applicationContext-service.xml]:
Cannot resolve reference to bean 'transactionInterceptor' while
setting bean property 'transactionInterceptor'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'transactionInterceptor' defined in class path
resource [applicationContext-service.xml]: Cannot resolve reference to
bean 'transactionManager' while setting bean property
'transactionManager'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'transactionManager' defined in class path
resource [applicationContext-service.xml]: Cannot resolve reference to
bean 'sessionFactory' while setting bean property 'sessionFactory';
nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'sessionFactory' defined in class path
resource [applicationContext-service.xml]: Invocation of init method
failed; nested exception is org.hibernate.HibernateException: Unable
to get the default Bean Validation factory

Categories

Resources