[RESOLVIDO] Spring - Ajuda básica

Boa noite a todos,

Estou tentando aprender a utilizar o Spring (tenho lido tudo o que acho sobre, mas acho, digo, tenho certeza que ainda não peguei o “espírito” do IOC/ID). E resolvi utilizar em um projeto onde estou tentando projetar a camada de persistência. Neste projeto estou utilizando o Spring junto com o Struts, não sei se isso interfere em alguma coisa. Bom… Estou obtendo o seguinte erro:

09/11/2012 22:28:25 org.apache.catalina.core.StandardContext listenerStart
GRAVE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'AreaDeTextoDAO' defined in file [C:\Users\Juba\Documents\Novos_PrOgRaMaS\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\jubernate\WEB-INF\classes\jubernate\dao\AreaDeTextoDAO.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [jubernate.dao.AreaDeTextoDAO]: No default constructor found; nested exception is java.lang.NoSuchMethodException: jubernate.dao.AreaDeTextoDAO.<init>()
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1568)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1558)
	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [jubernate.dao.AreaDeTextoDAO]: No default constructor found; nested exception is java.lang.NoSuchMethodException: jubernate.dao.AreaDeTextoDAO.<init>()
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:72)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:990)
	... 23 more
Caused by: java.lang.NoSuchMethodException: jubernate.dao.AreaDeTextoDAO.<init>()
	at java.lang.Class.getConstructor0(Unknown Source)
	at java.lang.Class.getDeclaredConstructor(Unknown Source)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:67)
	... 24 more

A classe do erro é esta:

@Component("AreaDeTextoDAO")
public class AreaDeTextoDAO implements ServiceDao<AreaDeTexto>{

	static Logger logger = Logger.getLogger(AreaDeTextoDAO.class);
	
	
	private EntityManager em;
	
	@Inject
	public AreaDeTextoDAO(DAOFactory dao) {
		this.em = dao.getEm();
	}

	public boolean salvar(AreaDeTexto e) {
		logger.debug("Iniciando a tarefa de gravação de uma area de texto - cod:\t" + e.getCodigo());
		if(e.getCodigo() == 0)
			return add(e);
		else
			return alterar(e);
		
	}

	public boolean add(AreaDeTexto e) {
		logger.debug("Gravando nova area de texto - cod:\t" + e.getCodigo());
		EntityTransaction trans = em.getTransaction();
		try{     	
			trans.begin();
			logger.debug("Inserindo area de texto");
			em.persist(e);
			trans.commit();
			return true;
		}catch(Exception erro){
			logger.debug("Erro durante a inserção dos dados!!!");
			erro.printStackTrace();
			return false;
		}
	}

	public List<AreaDeTexto> getCol() {
		logger.debug("Consultando todas as áreas de texto");
		try {
			
			TypedQuery<AreaDeTexto> query = em.createNamedQuery("AreaDeTexto.findAll", AreaDeTexto.class);
			return query.getResultList();
		} catch (NoResultException re) {
			logger.error("A consulta falhou -  Não há resultados", re);
			re.printStackTrace();
			return null;		
		} catch (RuntimeException re) {
			logger.error("A consulta falhou - Falha em tempo de execução", re);
			re.printStackTrace();
			throw re;
		}	}

	public AreaDeTexto getProximo(AreaDeTexto e) {
		logger.debug("Consultando a próxima area de texto após o código:\t" + e.getCodigo());

		try {
			TypedQuery<AreaDeTexto> query = em.createNamedQuery("AreaDeTexto.findNext", AreaDeTexto.class);
			query.setParameter("codigo", e.getCodigo());
			query.setMaxResults(1);
			return (AreaDeTexto) query.getSingleResult();
		}catch(NoResultException re){
			logger.debug("Não há mais áreas de texto após o código:\t" + e.getCodigo());
			return null;
		}catch (RuntimeException re) {
			logger.error("A consulta falhou - Falha em tempo de execução", re);
			throw re;
		}		

	}

	public AreaDeTexto getAnterior(AreaDeTexto e) {
		logger.debug("Consultando a area de texto anterior ao código:\t" + e.getCodigo());

		try {
			TypedQuery<AreaDeTexto> query = em.createNamedQuery("AreaDeTexto.findPrevious", AreaDeTexto.class);

			query.setParameter("codigo", e.getCodigo());
			query.setMaxResults(1);
			return (AreaDeTexto) query.getSingleResult();
		}catch(NoResultException re){
			logger.debug("Não há mais áreas de texto antes do código:\t" + e.getCodigo());
			return null;
		}catch (RuntimeException re) {
			logger.error("A consulta falhou - Falha em tempo de execução", re);
			throw re;
		}		
	}

	public AreaDeTexto getPorChave(double chave) {
		logger.debug("Consultando a area de texto que possua o código:\t" + (long)chave);

		try {
			TypedQuery<AreaDeTexto> query = em.createNamedQuery("AreaDeTexto.findByCodigo", AreaDeTexto.class);

			query.setParameter("codigo", (long)chave);
			query.setMaxResults(1);
			return (AreaDeTexto) query.getSingleResult();
		}catch(NoResultException re){
			logger.debug("Não há mais áreas de texto antes do código:\t" + chave, re);
			re.printStackTrace();
			return null;
		}catch (RuntimeException re) {
			logger.error("A consulta falhou - Falha em tempo de execução", re);
			throw re;
		}		
	}
	
	public AreaDeTexto getPrimeiro(){
		logger.debug("Consultando a primeira area de texto");

		try {
			TypedQuery<AreaDeTexto> query = em.createNamedQuery("AreaDeTexto.findFirst", AreaDeTexto.class);
			query.setMaxResults(1);
			return (AreaDeTexto) query.getSingleResult();
		}catch(NoResultException re){
			logger.debug("Não há áreas de texto cadastradas no banco de dados");
			return null;
		}catch (RuntimeException re) {
			logger.error("A consulta falhou - Falha em tempo de execução", re);
			throw re;
		}			
		
	}

	public boolean alterar(AreaDeTexto e) {
		logger.debug("Iniciando a tarefa de gravação do objeto " + e.getClass().getSimpleName());
		EntityTransaction trans = em.getTransaction();
		try{
			trans.begin();

			logger.debug("Atualizando dados na tabela");
			em.merge(e);
			trans.commit();
			return true;
		}catch(Exception erro){
			logger.debug("Erro durante o processo de atualização");
			trans.rollback();
			erro.printStackTrace();
			return false;
		}
	}

	public boolean excluir(AreaDeTexto e) {
		logger.debug("Iniciando a exclusão de uma área de texto - cod:\t" + e.getCodigo());
		EntityTransaction trans = em.getTransaction();
		try{
			
			trans.begin();
			em.remove(e);
			trans.commit();
			logger.debug("Exclusão realizada com sucesso");
			return true;
		}catch(RollbackException er){
			logger.debug("Falha ao excluir\nErro: " + er);
			trans.rollback();
		}
		return false;

	}
	
	
}

A classe DAOFactory:

@Component("DAOFactory")
public class DAOFactory {


	private EntityManagerFactory emf;
	private EntityManager em;
		
	public DAOFactory() {

		emf =
			    Persistence.createEntityManagerFactory("projeto2");
		
				em = emf.createEntityManager();
	}

	
	
	public EntityManager getEm() {
		return em;
	}



}

A classe AreaDeTextoDAO implementa esta interface:

public interface ServiceDao<T> {

	public boolean salvar(T e);
	public boolean add(T e);
	public List<T> getCol();
	public T getProximo(T e);
	public T getAnterior(T e);
	public T getPorChave(double chave);
	public T getPrimeiro();
	public boolean alterar(T e);
	public boolean excluir(T e);
	
}

O meu 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:context="http://www.springframework.org/schema/context"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

	<context:annotation-config/>
    <context:component-scan base-package="jubernate.dao" />

</beans>

Não sei se postei muito código, mas é que realmente estou perdido. Nunca usei o Spring e só agora que estou tomando contanto com os conceitos da ferramenta. Como o erro fala de construtor eu já tentei alterar o construtor, já tentei criar um padrão. Mas nada até agora deu resultado e como não tenho muito conhecimento sobre, estou perdido.

Agradeço a ajuda desde já.

Inté…

Jubarius, blza brother, tente criar um Construtor sem parâmetros no seu AreaDeTextoDAO, o stacktrace está reclamando isso.

Blz ibotirama,

Realmente era isso. Incrível como na maioria das vezes a solução dos problemas estão nas coisas mais simples do mundo.

Vlw