Spring 3 problemas ao fazer injeção de dependencia

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"&gt;


&lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;

&lt;context:annotation-config /&gt;

&lt;context:component-scan base-package="com.ethru.mensagerianfe"/&gt;

&lt;context:property-placeholder location="*/jdbcMySQL.properties" /&gt;

&lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
    &lt;property name="driverClassName"&gt;
        &lt;value&gt;${jdbc.driverClassName}&lt;/value&gt;
    &lt;/property&gt;
    &lt;property name="url"&gt;
        &lt;value&gt;${jdbc.url}&lt;/value&gt;
    &lt;/property&gt;
    &lt;property name="username"&gt;
        &lt;value&gt;${jdbc.username}&lt;/value&gt;
    &lt;/property&gt;
    &lt;property name="password"&gt;
        &lt;value&gt;${jdbc.password}&lt;/value&gt;
    &lt;/property&gt;
&lt;/bean&gt;

&lt;bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
    &lt;property name="dataSource" ref="dataSource" /&gt;
    &lt;property name="persistenceUnitName" value="PersistenceFactory" /&gt;
    &lt;property name="jpaVendorAdapter"&gt;
        &lt;bean
            class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
            &lt;property name="showSql" value="true" /&gt;
            &lt;property name="generateDdl" value="false" /&gt; 
            &lt;property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" /&gt;
        &lt;/bean&gt;
    &lt;/property&gt;      
&lt;/bean&gt;

&lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
    &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
    &lt;property name="dataSource" ref="dataSource" /&gt;
&lt;/bean&gt;

</beans>[/code]

Meu GenericJpa

[code]@SuppressWarnings({“rawtypes”, “unchecked”})
public abstract class GenericJpaDao<T, ID extends Serializable> {

private Class&lt;T&gt; 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&lt;Empresa&gt; 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.

Olá Amigo,

Tente utilizar a anotação @Resource conforme descrito abaixo:

@Resource
private Class entityBeanType;

Espero ter ajudado,
Abraços

fazendo essa alteracao me retorna a seguinte exception

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'EmpresaDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [java.lang.Class] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)} at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:300) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4681) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5184) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5179) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [java.lang.Class] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:431) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:541) at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:297) ... 21 more

rapz, com jsf da esse problema mesmo. nao sei se eh alguma incompatibilidade com o spring 3 e o jsf 2 mas no meu caso um colega aqui do guj deu a solucao. ou eu achei no blog dele na internet. Voce resolve assim:

import javax.inject.Named;

@Named(value = "empresaDao")
public class EmpresaDaoImpl extends GenericJpaDao<Empresa, Serializable>  
        implements Serializable, EmpresaDao {  
} 
import javax.inject.Inject;
import org.springframework.stereotype.Service;


@Service(value="empresaService")  
public class EmpresaServiceImpl implements Serializable, EmpresaService {  
  
    @Inject
    private EmpresaDao dao;  
  
    @Override  
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor=RuntimeException.class)  
    public Empresa atualiza(Empresa e) {  
        return dao.atualiza(e);  
    }
import javax.faces.bean.ManagedProperty;

@ManagedBean  
@SessionScoped  
public class EmpresaController implements Serializable{  
  
    private Empresa empresa;  
    private DataModel<Empresa> listaEmp;  
      
    @ManagedProperty(name = "empresaService", value = "#{empresaService}")
    private EmpresaService service;

voce vai precisar baixar o javax.inject (Java EE6) JSR-330
http://docs.oracle.com/javaee/6/api/javax/inject/package-summary.html

download aquihttp://code.google.com/p/atinject/downloads/detail?name=javax.inject.zip&can=2&q=

se voce quiser resolver sem essas alteracoes… mas acho q nao eh a forma certa de fazer isso basta voce colocar a anotacao @Component no managedbean

@ManagedBean  
@SessionScoped  
@Component
public class EmpresaController implements Serializable{  
  
    private Empresa empresa;  
    private DataModel<Empresa> listaEmp;  
      
    @ManagedProperty(name = "empresaService", value = "#{empresaService}")
    private EmpresaService service;