Pessoal alguem pode me ajudar com problema de injeção do spring?
Ao executar o teste de uma classe esta retornando null para o entityManager.
Segue a arquiterura
NetBeans 6.5
Spring 2.5.6
Hibernate 3
MySql
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:tx="http://www.springframework.org/schema/tx"
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">
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="BovespaPU" />
</bean>
<!-- Classe responsável pela injeção do EntityManager nas classes que usam a anotação @PersistenceContext -->
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="false" />
<bean id="tipoDao" class="br.com.bovespa.dao.imp.TipoDaoImp">
<constructor-arg ref="entityManagerFactory"></constructor-arg>
</bean>
</beans>
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="BovespaPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>br.com.bovespa.entities.Tipo</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
<property name="transaction.factory_class" value="org.hibernate.transaction.jdbctransactionfactory" />
<property name="hibernate.connection.username" value="username"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.password" value="123456"/>
<property name="hibernate.connection.url" value="jdbc:mysql://hots/banco"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
</properties>
</persistence-unit>
</persistence>
TipoDaoImpTest.java
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:**/applicationContext*.xml"})
@TestExecutionListeners({})
public class TipoDaoImpTest {
private TipoDaoImp tipoDao;
private Integer id = 1;
public TipoDaoImpTest() {
}
@Test
public void testSalvar() {
Tipo tipo = null;
tipo = getTipoDao().salvar(getTipo());
assertNotNull(tipo);
assertEquals(id, tipo.getId());
assertEquals("Teste", tipo.getNome());
}
Trechos da classe
DaoGenericoImp.java
@Repository
public class DaoGenericoImp<T, ID extends Serializable> implements DaoGenerico<T, ID> {
@PersistenceContext
private EntityManager entityManager;
gets e sets omitidos
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public T salvar(T object) {
try {
entityManager.persist(object);
entityManager.getTransaction().commit();
return object;
} finally {
if (entityManager != null) {
entityManager.close();
}
}
}
sou novato e desde já peço desculpas por falhas grosseiras…
Obrigado