Estou iniciando estudo com Spring e me deparei com um problema na hora de fazer a injeção do EntityManager, ou melhor qualquer tipo de injeção
segue o applicationContext
[code]<?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:tx=“http://www.springframework.org/schema/tx”
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<tx:annotation-driven transaction-manager="transactionManager"/>
<context:annotation-config />
<context:component-scan base-package="com.ethru.mensagerianfe"/>
<context:property-placeholder location="*/jdbcMySQL.properties" />
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>${jdbc.driverClassName}</value>
</property>
<property name="url">
<value>${jdbc.url}</value>
</property>
<property name="username">
<value>${jdbc.username}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="PersistenceFactory" />
<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.MySQL5InnoDBDialect" />
</bean>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
</beans>[/code]
Meu GenericJpa
[code]@SuppressWarnings({“rawtypes”, “unchecked”})
public abstract class GenericJpaDao<T, ID extends Serializable> {
private Class<T> entityBeanType;
@PersistenceContext
protected EntityManager em;[/code]
o DaoImpl
[code]@Repository(“EmpresaDao”)
public class EmpresaDaoImpl extends GenericJpaDao<Empresa, Serializable>
implements Serializable, EmpresaDao {
}[/code]
o EmpresaServiceImpl
[code]
package com.ethru.mensagerianfe.service.impl;
@Service(“EmpresaService”)
public class EmpresaServiceImpl implements Serializable, EmpresaService {
@Autowired
private EmpresaDao dao;
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor=RuntimeException.class)
public Empresa atualiza(Empresa e) {
return dao.atualiza(e);
}[/code]
e o Empresa Controller
[code]
package com.ethru.mensagerianfe.controller;
@ManagedBean
@SessionScoped
public class EmpresaController implements Serializable{
private Empresa empresa;
private DataModel<Empresa> listaEmp;
@Autowired
private EmpresaService service;[/code]
mas nenhuma injeção funciona os objeto ficam nulos, tanto no PersisteceContext quanto nos dao, o que estou fazendo de errado?
todas as classes estao no pacote com.ethru.mensagerianfe
Obrigado.