Cannot convert value of type [org.hibernate.impl.SessionFactoryImpl] to required type [com.liferay.portal.kernel.dao.orm.SessionFactory] - spring

I got this exception!!!
Caused by: java.lang.IllegalStateException: Cannot convert value of type [org.hibernate.impl.SessionFactoryImpl] to required type [com.liferay.portal.kernel.dao.orm.SessionFactory] for property 'sessionFactory': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:289)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:154)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:452)
... 41 more
Do you have any solution?

One of the beans that you pass sessionFactory to them require the Liferay one instead of the Hibernate one.
There are 2 possible mistakes:
You made a mistake in wiring - fix that by passing Lifray's SessionFactory (create one if you don't have one already)
The mistake is in Java class imports - fix the imports

Related

Grails 2.4.3 Upgrade - Spring Security ACl - SpelExpressionParser

Getting the below error while running the app, no issues during compile. Kindly help, how to fix this issue.
ERROR [localhost-startStop-1] 2014-09-26 19:19:19,050 org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener.error(213) : Error initializing the application: Error creating bean with name 'flowBuilderServices': Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.expression.spel.standard.SpelExpressionParser' to required type 'org.springframework.binding.expression.ExpressionParser' for property 'expressionParser'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.expression.spel.standard.SpelExpressionParser] to required type [org.springframework.binding.expression.ExpressionParser] for property 'expressionParser': no matching editors or conversion strategy found
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flowBuilderServices': Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.expression.spel.standard.SpelExpressionParser' to required type 'org.springframework.binding.expression.ExpressionParser' for property 'expressionParser'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.expression.spel.standard.SpelExpressionParser] to required type [org.springframework.binding.expression.ExpressionParser] for property 'expressionParser': no matching editors or conversion strategy found
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.expression.spel.standard.SpelExpressionParser' to required type 'org.springframework.binding.expression.ExpressionParser' for property 'expressionParser'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.expression.spel.standard.SpelExpressionParser] to required type [org.springframework.binding.expression.ExpressionParser] for property 'expressionParser': no matching editors or conversion strategy found
... 4 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [org.springframework.expression.spel.standard.SpelExpressionParser] to required type [org.springframework.binding.expression.ExpressionParser] for property 'expressionParser': no matching editors or conversion strategy found
What plugins are you using? I was getting the same exception when upgrading to Grails 2.4.3 and just narrowed it down (it wasn't easy) to the fact that the Grails WebFlow plugin and the ACL plugin both setup a bean named expressionParser, but each plugin is using a different class... one is overwriting the other during Grails initialization of spring beans. By renaming the web flow plugin's expressionParser to flowExpressionParser in the WebFlowPluginSupport.groovy file, I was able to get around this exception. You could search in your plugins directory for 'expressionParser' and see if you have >1 plugin using it.
I have let the webflow plugin folks know, and a bit more detail here.
https://jira.grails.org/browse/GPWEBFLOW-109

Cannot convert value of type [org.springframework.core.env.StandardEnvironment] to required type

I try to upgrade spring from 3.0 to 3.2.8, but I receive the following error
Cannot convert value of type [org.springframework.core.env.StandardEnvironment] to required type [xxx] for property 'environment': no matching editors or conversion strategy found
I guess its some name conflict to an new class StandardEnvironment, but I don't find any place that defines the property 'environment'
Any help please?
It seems that I have a function called setEnvironment which is in conflict with some spring builtin function setEnvironment which is used to set StandardEnvironment when initialize spring framework, so I changed function name to something else, so it worked. really weird problem.
Here is your issue:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'backOfficeContext' defined in class path resource [se/softronic/appia/cache/DomainSpecificEhCacheBeanPostProcessorTest-context.xml]:
The class for bean 'backOfficeContext' contains property BackOfficeEnvironment environment
So, just change the environment property name to something another, or get rid of default-autowire="byName" and just rely on byType by default.

Spring AOP IllegalArgumentException: Cannot convert value of type [$Proxy12

I am trying to configure one advice in an existing spring project.
Following configuration works fine for a single package but when pointcut expression try to apply that advice on all packages its giving following error.
My Configuration:
<aop:config>
<aop:pointcut id="loggingPointcut" expression="execution(* com.abc.businessprocess.operation..*.execute(..))" />
<aop:advisor id="methodLoggingAdvisor" advice-ref="methodLoggingAdvice" pointcut-ref="loggingPointcut" />
</aop:config>
I tried with annotation also but it was giving same error.
I tried with CGLIB also even after using that its giving same error.
Error:
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy12 implementing com.fmr.ast.common.businessprocess.util.Timeable,com.fmr.ast.common.businessprocess.operation.Operation,com.fmr.commons.taskmanager.core.Task,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.fmr.ips.businessprocess.operation.goalsetup.GetLeveledIRGExpInc] for property 'getRawDetailedLeveledExpInc'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy12 implementing com.fmr.ast.common.businessprocess.util.Timeable,com.fmr.ast.common.businessprocess.operation.Operation,com.fmr.commons.taskmanager.core.Task,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.fmr.ips.businessprocess.operation.goalsetup.GetLeveledIRGExpInc] for property 'getRawDetailedLeveledExpInc': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1250)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
... 33 more
Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy12 implementing com.fmr.ast.common.businessprocess.util.Timeable,com.fmr.ast.common.businessprocess.operation.Operation,com.fmr.commons.taskmanager.core.Task,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.fmr.ips.businessprocess.operation.goalsetup.GetLeveledIRGExpInc] for property 'getRawDetailedLeveledExpInc': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
... 37 more
Looking at the exception trace this is what I suspect:
GetLeveledIRGExpInc is a concrete class that implements three interfaces: Timeable, Operation, Task. You have a bean of this type declared in your context, which gets proxied because of your AOP config. This means that the runtime type of the bean won't be GetLeveledIRGExpInc any more, it will be $Proxy12 (JDK proxy) which still implements the above three interfaces, but is not a subtype of the concrete class GetLeveledIRGExpInc.
There is another bean somewhere in your context that needs a bean of this type to be injected into a property named getRawDetailedLeveledExpInc. When Spring tries to inject the proxied bean into that property, it fails, because the property's type is incompatible with the bean's runtime type.
The fundamental problem is that you try to apply a very generic logging aspect using JDK proxying mechanism which can only advise methods declared on interfaces. Try using <aop:config proxy-target-class="true"> so that classes without implemented interfaces can be advised as well. This would resolve the above detailed problem, as the generated CGLIB proxy for GetLeveledIRGExpInc will actually be a subtype of it. (Don't forget to add cglib to your dependencies for this to work.)

Intellij incorrectly highlighting error in bean definition with spring

Could not autowire bean should be off type ..NamedPArameterJDBCTemplate
Which is wrong on two counts ... ?
There's a space at the beginning of your class attribute value in your XML file.

Error while injecting a Spring bean into a JSF ManagedBean

I have a JSF ManagedBean which has a property that should be set by Spring. However, I get the following error:
Caused by: javax.el.ELException: java.lang.IllegalArgumentException: Cannot convert persistence.AuthDao#2f6e6ad9 of type class $Proxy166 to class persistence.AuthDao
at com.sun.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:68)
at com.sun.faces.el.ELUtils.coerce(ELUtils.java:536)
at com.sun.faces.mgbean.BeanBuilder$Expression.evaluate(BeanBuilder.java:592)
at com.sun.faces.mgbean.ManagedBeanBuilder$BakedBeanProperty.set(ManagedBeanBuilder.java:606)
... 57 more
Caused by: java.lang.IllegalArgumentException: Cannot convert persistence.AuthDao#2f6e6ad9 of type class $Proxy166 to class persistence.AuthDao
at com.sun.el.lang.ELSupport.coerceToType(ELSupport.java:397)
at com.sun.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:66)
I have the ELresolver in faces-config.xml.
<managed-bean>
<managed-bean-name>authController</managed-bean-name>
<managed-bean-class>controllers.AuthController</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>authDao</property-name>
<value>#{authDao}</value>
</managed-property>
</managed-bean>
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
It seems that it can find the class, but the class is of another type ($Proxy166?, not sure where that comes from).
PS: Removing the ELResolver seems to do the trick; I thought explicitly providing managed-bean in faces-config.xml would override ELResolver. Is there any way of both of these to coexist, then? Similarly, if I provide both annotation and XML configuration for a bean, which one of these is preferred, or is there a way to merge them, provide some properties in annotation, some in XML?
PPS: After adding interfaces and changing my current classes to implement them, I get the following error:
Error occurred during deployment: Exception while loading the app :
java.lang.IllegalStateException: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'authDao' defined in ServletContext resource
[/WEB-INF/applicationContext.xml]: Initialization of bean failed;
nested exception is
org.springframework.beans.ConversionNotSupportedException: Failed to
convert property value of type '$Proxy157 implementing
persistence.UserDao,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised'
to required type 'persistence.UserDaoImpl' for property 'userDao';
nested exception is java.lang.IllegalStateException: Cannot convert
value of type [$Proxy157 implementing
persistence.UserDao,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised]
to required type [persistence.UserDaoImpl] for property 'userDao': no
matching editors or conversion strategy found. Please see server.log
for more details.
This is a proxy of your class. You are implementing an interface, so spring creates a proxy around the interface, but you are trying to inject by concrete type. Switch to the interface instead (in the managed bean).
If you really need for some reason to inject by concrete class, you can use #Scoped(proxyMode=ScopeProxyMode.TARGET_CLASS)

Resources