Hallo!
Ich versuche grade ein kleines Testprojekt mit Hibernate (mit Annotations) und Spring sowie einer Postgres Datenbank zu testen, leider bekomme ich immer folgende Exception:
meine Testklasse, welche von "AbstractTransactionalDataSourceSpringContextTests" ableitet - damit dachte ich eigentlich dass ich keine Dependency Probleme beim Test habe..
Und hier noch Konfigurationsdateien:
Ich versuche grade ein kleines Testprojekt mit Hibernate (mit Annotations) und Spring sowie einer Postgres Datenbank zu testen, leider bekomme ich immer folgende Exception:
Code:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'at.gv.brz.dao.impl.AdresseDaoTest': Unsatisfied dependency expressed through bean property 'adresseDao': Set this property value or disable dependency checking for this bean.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.checkDependencies(AbstractAutowireCapableBeanFactory.java:1184)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1006)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:329)
at org.springframework.test.AbstractDependencyInjectionSpringContextTests.injectDependencies(AbstractDependencyInjectionSpringContextTests.java:205)
at org.springframework.test.AbstractDependencyInjectionSpringContextTests.prepareTestInstance(AbstractDependencyInjectionSpringContextTests.java:180)
at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:100)
at junit.framework.TestCase.runBare(TestCase.java:132)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
meine Testklasse, welche von "AbstractTransactionalDataSourceSpringContextTests" ableitet - damit dachte ich eigentlich dass ich keine Dependency Probleme beim Test habe..
Java:
package at.gv.brz.dao.impl;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
import at.gv.brz.domain.Adresse;
public class AdresseDaoTest extends
AbstractTransactionalDataSourceSpringContextTests {
private AdresseDao adresseDao;
@Override
protected void onSetUpInTransaction() throws Exception {
}
public void testSpeicherAdresse() {
Adresse adresse = new Adresse("Ort123", 3214, "Hauptstrasse 1337");
Integer id = null;
id = this.adresseDao.speicherAdresse(adresse);
assertNotNull(id);
}
public void setAdresseDao(AdresseDao adresseDao) {
this.adresseDao = adresseDao;
}
@Override
protected String[] getConfigLocations() {
return new String[] { "applicationContext.xml" };
}
}
Java:
package at.gv.brz.dao.impl;
import org.hibernate.SessionFactory;
import at.gv.brz.dao.IAdresseDao;
import at.gv.brz.domain.Adresse;
public class AdresseDao implements IAdresseDao {
private SessionFactory sessionFactory;
public Adresse getAdresse(Integer adresseId) {
return (Adresse) this.sessionFactory.getCurrentSession().get(
Adresse.class, adresseId);
}
public Integer speicherAdresse(Adresse adresse) {
Integer ret = (Integer) this.sessionFactory.getCurrentSession().save(
adresse);
return ret;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
}
Java:
package at.gv.brz.dao.impl;
import org.hibernate.SessionFactory;
import at.gv.brz.dao.IPersonDao;
public class PersonDao implements IPersonDao {
private SessionFactory sessionFactory;
public PersonDao getPerson(Integer personId) {
return (PersonDao) this.sessionFactory.getCurrentSession().get(
PersonDao.class, personId);
}
public Integer speicherPerson(PersonDao person) {
Integer ret = (Integer) this.sessionFactory.getCurrentSession().save(
person);
return ret;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
}
Und hier noch Konfigurationsdateien:
Java:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
default-autowire="byType">
<import resource="databaseContext.xml" />
<import resource="transactionContext.xml" />
<bean id="adresseDao" class="at.gv.brz.dao.impl.AdresseDao">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- rem: can't use dependency-check="objects" -->
<bean id="personDao" class="at.gv.brz.dao.impl.PersonDao">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
Java:
<?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="
[url=http://www.springframework.org/schema/beans]Index of /schema/beans[/url] [url]http://www.springframework.org/schema/beans/spring-beans-2.0.xsd[/url]
[url=http://www.springframework.org/schema/jee]Index of /schema/jee[/url] http://www.springframework.org/schema/jee/spring-jee-2.0.xsd"
default-autowire="byType">
<!-- hibernate template -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
<!-- property name="cacheQueries" value="true" /-->
</bean>
<!-- Database -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>at.gv.brz.domain.Adresse</value>
<value>at.gv.brz.domain.Person</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.jdbc.batch_size">0</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.cache.provider_class"> net.sf.ehcache.hibernate.SingletonEhCacheProvider
</prop>
</props>
</property>
</bean>
<!-- mit externen Properties ... -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${db.driverClass}" />
<property name="jdbcUrl" value="${db.jdbcUrl}" />
<property name="user" value="${db.user}" />
<property name="password" value="${db.password}" />
</bean>
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties" />
</bean>
</beans>
Java:
<?xml version="1.0" encoding="UTF-8"?>
<beans default-init-method="init" default-destroy-method="destroy"
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="
[url=http://www.springframework.org/schema/beans]Index of /schema/beans[/url] [url]http://www.springframework.org/schema/beans/spring-beans-2.0.xsd[/url]
[url=http://www.springframework.org/schema/tx]Index of /schema/tx[/url] [url]http://www.springframework.org/schema/tx/spring-tx-2.0.xsd[/url]
[url=http://www.springframework.org/schema/aop]Index of /schema/aop[/url] http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- deklarative Transaktion -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" propagation="REQUIRED" />
<tx:method name="select*" read-only="true" propagation="REQUIRED" />
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="daoMethods"
expression="execution(* at.gv.brz.dao.impl.*Dao*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethods" />
</aop:config>
<aop:aspectj-autoproxy />
<bean name="transactionTemplate"
class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="transactionManager" />
</bean>
</beans>
Zuletzt bearbeitet: