Hi
I have written a simple application consists of Hibernate-Spring and JSF, everthing works fine in the WebContainer. But when i test the services that are in the application with JUNIT, spring throws the following exception:
As i said before spring works well with the same configuration file in the web container. Configuratiın file:Code:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kullaniciGirisDAO' defined in class path resource [test/testContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [org.springframework.orm.hibernate.LocalSessionFactoryBean] to required type [net.sf.hibernate.SessionFactory] for property 'sessionFactory'] PropertyAccessExceptionsException (1 errors) org.springframework.beans.TypeMismatchException: Failed to convert property value of type [org.springframework.orm.hibernate.LocalSessionFactoryBean] to required type [net.sf.hibernate.SessionFactory] for property 'sessionFactory'
jUnit test class is:Code:<beans> <!-- ========================= Start of PERSISTENCE DEFINITIONS ========================= --> <!-- DataSource Definition --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"> <value>COM.ibm.db2.jdbc.app.DB2Driver</value> </property> <property name="url"> <value>jdbc:db2:xxxx</value> </property> <property name="username"> <value>xxxx</value> </property> <property name="password"> <value>xxx</value> </property> </bean> <!-- Hibernate SessionFactory Definition --> <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"> <property name="mappingResources"> <list> <value> maps/Tuserbl.hbm </value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> net.sf.hibernate.dialect.DB2Dialect </prop> <prop key="hibernate.connection.isolation">2</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> <property name="dataSource"> <ref bean="dataSource" /> </property> </bean> <!-- Spring Data Access Exception Translator Defintion --> <bean id="jdbcExceptionTranslator" class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator"> <property name="dataSource"> <ref bean="dataSource" /> </property> </bean> <!-- DAO Definition: Hibernate implementation --> <bean id="kullaniciGirisDAO" class="dao.impl.KullaniciGirisDAOImpl"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <!-- ========================= Start of SERVICE DEFINITIONS ========================= --> <!-- Hibernate Transaction Manager Definition --> <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory" /> </property> </bean> <!-- User Service Definition --> <bean id="kullaniciGirisServiceTarget" class=services.impl.KullaniciGirisServicesImpl"> <property name="kullaniciGirisDAO"> <ref local="kullaniciGirisDAO" /> </property> </bean> <!-- Transactional proxy for the User Service --> <bean id="kullaniciGirisService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"> <ref local="transactionManager" /> </property> <property name="target"> <ref local="kullaniciGirisServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="check*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean> </beans>
Any suggestion.Code:public class LogServicesImplTest extends TestCase { public static void main(String[] args) { TestRunner.run(LogServicesImplTest.class); } public void test_Log() { try { ApplicationContext xml = new ClassPathXmlApplicationContext("/test/testContext.xml"); DokumLogServicesImpl dokumLogServicesImpl = (DokumLogServicesImpl) xml .getBean("kullaniciGirisService"); ..... } catch (Exception e) { e.printStackTrace(); } } }
Thanks to everyone.


Reply With Quote