Weblogic and Spring JMS configuration throws java.lang.IllegalStateException - java

Converting EJB MDB application to Spring base JMS service.
JMS Queue configuration is in Weblogic server.
Have following in configuration in applicationContext XML file.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
<bean id="vTMessageQueueListener" class="com.collection.mom.sink.EventMessageBean" />
<bean id="queueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="jndiName">
<value>/jms/FilingTopicConnFact</value>
</property>
</bean>
<bean id="jmsDestinationResolver"
class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="cache">
<value>true</value>
</property>
</bean>
<bean id="QueueTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="queueConnectionFactory" />
</property>
<property name="destinationResolver">
<ref bean="jmsDestinationResolver" />
</property>
</bean>
<bean id="SMMessageQueue" class="org.springframework.jndi.JndiObjectFactoryBean">
<!--<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>-->
<property name="jndiName">
<value>com/vx/jms/vTMessageQueue</value>
</property>
</bean>
<bean id="V3JMSlistener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="concurrentConsumers" value="5" />
<property name="connectionFactory" ref="queueConnectionFactory" />
<property name="destinationName" ref="SMMessageQueue"/>
<property name="messageListener" ref="vTMessageQueueListener" />
</bean>
</beans>
.
<HTTP> <BEA-101162> <User defined listener org.springframework.web.context.ContextLoaderListener failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'V3JMSlistener' defined in class path resource [SpringJMSContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'weblogic.jms.common.DestinationImpl' to required type 'java.lang.String' for property 'destinationName'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'weblogic.jms.common.DestinationImpl' to required type 'java.lang.String' for property 'destinationName': no matching editors or conversion strategy found.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'V3JMSlistener' defined in class path resource [SpringJMSContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'weblogic.jms.common.DestinationImpl' to required type 'java.lang.String' for property 'destinationName'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'weblogic.jms.common.DestinationImpl' to required type 'java.lang.String' for property 'destinationName': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:584)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
Truncated. see log file for complete stacktrace
Caused By: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'weblogic.jms.common.DestinationImpl' to required type 'java.lang.String' for property 'destinationName'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'weblogic.jms.common.DestinationImpl' to required type 'java.lang.String' for property 'destinationName': no matching editors or conversion strategy found
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:590)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:604)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1697)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1653)
Truncated. see log file for complete stacktrace
Caused By: java.lang.IllegalStateException: Cannot convert value of type 'weblogic.jms.common.DestinationImpl' to required type 'java.lang.String' for property 'destinationName': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:299)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:585)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:604)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1697)
Truncated. see log file for complete stacktrace
Any help will be appreciated!!!

Use
<property name="destination" ref="SMMessageQueue"/>
instead of destinationName.
Spring can resolve a destination from its name but since you have the destination, you should inject that directly.

Related

Invalid property 'datasource' of bean class in spring

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:#localhost:1521:XE"></property>
<property name="username" value="SYSTEM"></property>
<property name="password" value="admin"></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="datasource" ref="datasource"></property>
<property name="annotatedClasses">
<list>
<value>spring.SpringORM.Student</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.oracl11gDialect</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="studnetDaoImplement" class="spring.SpringORM.StudnetDaoImplement">
<constructor-arg ref="hibernateTemplate" />
</bean>
</beans>
I am getting this error
NFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#3b0def13: defining beans [datasource,sessionFactory,hibernateTemplate,transactionManager,studnetDaoImplement]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [Application-context.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'datasource' of bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Bean property 'datasource' is not writable or has an invalid setter method. Did you mean 'dataSource'?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1344)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1067)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:545)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at spring.SpringORM.StudentTesting.main(StudentTesting.java:12)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'datasource' of bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Bean property 'datasource' is not writable or has an invalid setter method. Did you mean 'dataSource'?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1012)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:857)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1341)
... 13 more
org.springframework.beans.NotWritablePropertyException: Invalid property 'datasource' of bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Bean property 'datasource' is not writable or has an invalid setter method. Did you mean 'dataSource'? at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1012) at org.springfr
The stack trace is telling you enough. I have the same problems and solved it by renaming "datasource" to "dataSource". That thing is case sensitive so be careful. Hope that helps.

I can not have two datasources configured JPA Spring XML WildFly

Spring config in xml
<jee:jndi-lookup id="datas1" expected-type="javax.sql.DataSource"
jndi-name="java:/jndi1" />
<jee:jndi-lookup id="datas2" expected-type="javax.sql.DataSource"
jndi-name="java:/jndi2" />
<bean id="EntityM"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="datas1" />
<property name="packagesToScan" value="package.persistence.entity" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="false" />
<property name="databasePlatform" value="org.hibernate.dialect.Oracle12cDialect" />
</bean>
</property>
</bean>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="EntityM" />
</bean>
The Excpetion is:
Context initialization failed: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springSessionJdbcOperations' defined in class path resource [org/springframework/session/jdbc/config/annotation/web/http/JdbcHttpSessionConfiguration.class]: Unsatisfied dependency expressed through method 'springSessionJdbcOperations' parameter 0: No qualifying bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2: datas1,datas2; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2: datas1,jndi2.
I can not have two datasources configured, The first datasource is to the entityManagar and second datasource is to call stored procedure.
The JdbcSessionConfiguration expects a bean of type 'DataSource' with name 'dataSource'.
If this cannot be found, spring tries to use a bean of type 'DataSource', ignoring the name. Because there are two beans of this type, the exception is thrown.
Solution :
Rename the DataSource bean, that you want to use with the EntityManager from
'datas1' to 'dataSource'.
Spring should than be able to create JdbcSessionConfiguration and you can use the 'datas2' for whatever you need.

What's wrong with my persistence?

I use springmvc to build my project. But I have a problem:
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.connection.url"
value="jdbc:mysql://localhost:3306/springdemo"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="hukangze"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.connection.useUnicode" value="true"/>
<property name="hibernate.connection.characterEncoding" value="UTF-8"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.use_sql_comments" value="false"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.connection.autoReconnect" value="true"/>
<property name="connection.autoReconnectForPools" value="true"/>
<property name="connection.is-connection-validation-required" value="true"/>
</properties>
</persistence-unit>
</persistence>
mvc-dispatcher-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:component-scan base-package="com.ssh.controller"/>
<mvc:default-servlet-handler/>
<mvc:annotation-driven/>
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
<jpa:repositories base-package="com.ssh.repository"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="defaultPersistenceUnit"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" value="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
When I run it, I get this error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'javax.persistence.EntityManagerFactory' for property 'entityManagerFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'javax.persistence.EntityManagerFactory' for property 'entityManagerFactory': no matching editors or conversion strategy found
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'javax.persistence.EntityManagerFactory' for property 'entityManagerFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'javax.persistence.EntityManagerFactory' for property 'entityManagerFactory': no matching editors or conversion strategy found
Caused by: java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'javax.persistence.EntityManagerFactory' for property 'entityManagerFactory': no matching editors or conversion strategy found
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'javax.persistence.EntityManagerFactory' for property 'entityManagerFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'javax.persistence.EntityManagerFactory' for property 'entityManagerFactory': no matching editors or conversion strategy found
But when I undo this code in mvc-dispatcher-servlet.xml:
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" value="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
it's ok. What happens? What does that piece of code do?
Did you read exception fully? It is very detailed:
...property value of type 'java.lang.String' to required type
'javax.persistence.EntityManagerFactory' for property
'entityManagerFactory'...
Change this line:
<property name="entityManagerFactory" value="entityManagerFactory"/>
to this:
<property name="entityManagerFactory" ref="entityManagerFactory"/>

Invalid property 'connectionProperties' of bean class [org.apache.commons.dbcp.BasicDataSource]

I am getting this exception when initializing BasicDataSource. I want to pass Custom connection property to the dataSource.
My config is:
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'connectionProperties' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'connectionProperties' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1042)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:902)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1420)
I used this post from spring forum to resolve the issue.
Adding this bean solved my issue.
<bean
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"
lazy-init="false">
<property name="targetObject" ref="csdbDataSource" />
<property name="targetMethod" value="addConnectionProperty" />
<property name="arguments">
<list>
<value>defaultRowPrefetch</value>
<value>1</value>
</list>
</property>
</bean>

Error creating bean if have #Repository or a PersistenceExceptionTranslationPostProcessor bean

I am a rookie in spring and I am learning spring using the book Spring Recipes: A problem solution approach by Gary Mak.
Anyway I had this problem while using
PersistenceExceptionTranslationPostProcessor.
Here is my applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<context:property-placeholder location="jdbc.properties"/>
<tx:annotation-driven proxy-target-class="true" />
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"
value="${jdbc.driverClassName}" />
<property name="url"
value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- <property name="configLocation" value="classpath:hibernate.cfg.xml" /> -->
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>com/hibernateproj2/domain/Employee.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="employeeDaoImpl" class="com.hibernateproj2.dao.EmployeeDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="hibWorker" class="HibWorker" >
<property name="employeeDaoImpl" ref="employeeDaoImpl" />
</bean>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
</beans>
...................
#Repository
public class EmployeeDaoImpl implements EmployeeDao{
...........
}
public class HibWorker implements Worker{
.......................
#Transactional
public void doTrans(){
......................
}
...............
}
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
In this case i am getting the below error while loading the applicationContext.xml
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext .xml");
log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibWorker' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy5 implementing com.hibernateproj2.dao.EmployeeDao,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.hibernateproj2.dao.EmployeeDaoImpl] for property 'employeeDaoImpl'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy5 implementing com.hibernateproj2.dao.EmployeeDao,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.hibernateproj2.dao.EmployeeDaoImpl] for property 'employeeDaoImpl': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at Main.main(Main.java:10)
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy5 implementing com.hibernateproj2.dao.EmployeeDao,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.hibernateproj2.dao.EmployeeDaoImpl] for property 'employeeDaoImpl'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy5 implementing com.hibernateproj2.dao.EmployeeDao,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.hibernateproj2.dao.EmployeeDaoImpl] for property 'employeeDaoImpl': 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:1288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1249)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
... 14 more
Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy5 implementing com.hibernateproj2.dao.EmployeeDao,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.hibernateproj2.dao.EmployeeDaoImpl] for property 'employeeDaoImpl': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:219)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
... 18 more
but when i comment out #Repository annotation on EmployeeDaoImpl or if I comment out PersistenceExceptionTranslationPostProcessor bean declaration, then the applicationContext loads properly.
<!-- <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> -->
or
//#Repository
public class EmployeeDaoImpl implements EmployeeDao{
...........
}
I would like to know why this is happening. Could anyone please explain me this.
Type of HibWorker.employeeDaoImpl is EmployeeDaoImpl, therefore exception translation proxy of type HibernateDao can't be assigned to it.
Generally it's a bad practise to restrict implementation of dependencies this way, you should use interface (EmployeeDao) when declaring dependencies instead. If you follow that way, you also don't need proxy-target-class = "true" on <tx:annotation-driven>.
Alternative solution is to enable target class proxying for PersistenceExceptionTranslationPostProcessor.
See also:
7.6 Proxying mechanisms

Categories