VRaptor 3.0.2 com @Resource dentro de um jar

Olá!

Eu meu projeto compartilho os objetos do modelo do banco (Daos, Session do Hibernate, etc) de um outro projeto e estou tendo dificuldades de fazer o VRaptor encontrar o DaoFactory.

No projeto compartilhado, defini o tipo DaoFactory como @Resource, exportei-o como jar e inclui no projeto web. O DaoFactory ficou assim:

package net.danieljurado.dialer.dao;

import net.danieljurado.dialer.dao.modelo.ArquivoImportacao;
import net.danieljurado.dialer.dao.modelo.DefinicaoPadrao;
import net.danieljurado.dialer.dao.modelo.DiaSemana;
import net.danieljurado.dialer.dao.modelo.HistoricoCliente;
import net.danieljurado.dialer.dao.modelo.HistoricoLigacao;
import net.danieljurado.dialer.dao.modelo.InformacaoCliente;
import net.danieljurado.dialer.dao.modelo.MelhorHorarioContato;
import net.danieljurado.dialer.dao.modelo.Periodo;
import net.danieljurado.dialer.dao.modelo.ReagendamentoResultadoLigacao;
import net.danieljurado.dialer.dao.modelo.TipoTelefone;
import net.danieljurado.dialer.dao.util.HibernateUtil;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.caelum.vraptor.Resource;

@Resource
public final class DaoFactory {
	private final Session session;
	private Transaction transaction;

	public DaoFactory() {
		this.session = HibernateUtil.getSession();
	}

	public void beginTransaction() {
		this.transaction = this.session.beginTransaction();
	}

	public void close() {
		this.session.close();
	}

	public void commit() {
		this.transaction.commit();
		this.transaction = null;
	}

	public AgendamentoDao getAgendamentoDao() {
		return new AgendamentoDao(this.session);
	}

	public AgenteDao getAgenteDao() {
		return new AgenteDao(this.session);
	}

	public Dao<ArquivoImportacao> getArquivoImportacaoDao() {
		return new Dao<ArquivoImportacao>(this.session, ArquivoImportacao.class);
	}

	public CampanhaDao getCampanhaDao() {
		return new CampanhaDao(this.session);
	}

	public ClienteDao getClienteDao() {
		return new ClienteDao(this.session);
	}

	public ClienteReservadoDao getClienteReservadoDao() {
		return new ClienteReservadoDao(this.session);
	}

	public DefinicaoDao getDefinicaoDao() {
		return new DefinicaoDao(this.session);
	}

	public Dao<DefinicaoPadrao> getDefinicaoPadraoDao() {
		return new Dao<DefinicaoPadrao>(this.session, DefinicaoPadrao.class);
	}

	public Dao<DiaSemana> getDiaSemanaDao() {
		return new Dao<DiaSemana>(this.session, DiaSemana.class);
	}

	public EstadoClienteDao getEstadoClienteDao() {
		return new EstadoClienteDao(this.session);
	}

	public GrupoDao getGrupoDao() {
		return new GrupoDao(this.session);
	}

	public Dao<HistoricoCliente> getHistoricoClienteDao() {
		return new Dao<HistoricoCliente>(this.session, HistoricoCliente.class);
	}

	public Dao<HistoricoLigacao> getHistoricoLigacaoDao() {
		return new Dao<HistoricoLigacao>(this.session, HistoricoLigacao.class);
	}

	public Dao<InformacaoCliente> getInformacaoClienteDao() {
		return new Dao<InformacaoCliente>(this.session, InformacaoCliente.class);
	}

	public MailingDao getMailingDao() {
		return new MailingDao(this.session);
	}

	public Dao<MelhorHorarioContato> getMelhorHorarioContatoDao() {
		return new Dao<MelhorHorarioContato>(this.session,
				MelhorHorarioContato.class);
	}

	public MotivoFinalizacaoDao getMotivoFinalizacaoDao() {
		return new MotivoFinalizacaoDao(this.session);
	}

	public OrdemDao getOrdemDao() {
		return new OrdemDao(this.session);
	}

	public Dao<Periodo> getPeriodoDao() {
		return new Dao<Periodo>(this.session, Periodo.class);
	}

	public Dao<ReagendamentoResultadoLigacao> getReagendamentoResultadoLigacaoDao() {
		return new Dao<ReagendamentoResultadoLigacao>(this.session,
				ReagendamentoResultadoLigacao.class);
	}

	public ResultadoLigacaoDao getResultadoLigacaoDao() {
		return new ResultadoLigacaoDao(this.session);
	}

	public RotaDao getRotaDao() {
		return new RotaDao(this.session);
	}

	public ServicoDao getServicoDao() {
		return new ServicoDao(this.session);
	}

	public TelefoneDao getTelefoneDao() {
		return new TelefoneDao(this.session);
	}

	public Dao<TipoTelefone> getTipoTelefoneDao() {
		return new Dao<TipoTelefone>(this.session, TipoTelefone.class);
	}

	public UsuarioDao getUsuarioDao() {
		return new UsuarioDao(this.session);
	}

	public boolean hasTransaction() {
		return this.transaction != null;
	}

	public void rollback() {
		this.transaction.rollback();
		this.transaction = null;
	}
}

Inclui o jar exportado pelo Eclipse no WEB-INF/lib.

O projeto é compilado corretamente, porém quando executo-o no tomcat, recebo a seguinte mensagem:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'daoFactoryInterceptor' defined in file [C:\Users\Daniel Jurado\Documents\Trabalho\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\dialerWeb\WEB-INF\classes\net\danieljurado\dialerWeb\interceptors\DaoFactoryInterceptor.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [net.danieljurado.dialer.dao.DaoFactory]: : No unique bean of type [net.danieljurado.dialer.dao.DaoFactory] is defined: Unsatisfied dependency of type [class net.danieljurado.dialer.dao.DaoFactory]: expected at least 1 matching bean; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [net.danieljurado.dialer.dao.DaoFactory] is defined: Unsatisfied dependency of type [class net.danieljurado.dialer.dao.DaoFactory]: expected at least 1 matching bean
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:591)
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:193)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:835)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
	at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:302)
	at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:43)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:308)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:297)
	at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:942)
	at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:224)
	at br.com.caelum.vraptor.ioc.spring.VRaptorApplicationContext.getBean(VRaptorApplicationContext.java:209)
	at br.com.caelum.vraptor.ioc.spring.SpringBasedContainer.instanceFor(SpringBasedContainer.java:61)
	at br.com.caelum.vraptor.util.collections.Functions$1.apply(Functions.java:32)
	at br.com.caelum.vraptor.util.collections.Functions$1.apply(Functions.java:30)
	at com.google.common.collect.Lists$TransformingRandomAccessList.get(Lists.java:425)
	at java.util.AbstractList$Itr.next(Unknown Source)
	at com.google.common.collect.Iterators$7.computeNext(Iterators.java:572)
	at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:135)
	at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:130)
	at com.google.common.collect.Lists.newArrayList(Lists.java:129)
	at com.google.common.collect.Collections2$FilteredCollection.toArray(Collections2.java:229)
	at br.com.caelum.vraptor.interceptor.DefaultInterceptorRegistry.interceptorsFor(DefaultInterceptorRegistry.java:50)
	at br.com.caelum.vraptor.interceptor.InterceptorListPriorToExecutionExtractor.intercept(InterceptorListPriorToExecutionExtractor.java:42)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:46)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:59)
	at br.com.caelum.vraptor.interceptor.FlashInterceptor.intercept(FlashInterceptor.java:80)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:46)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:59)
	at br.com.caelum.vraptor.interceptor.ResourceLookupInterceptor.intercept(ResourceLookupInterceptor.java:67)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:46)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:59)
	at br.com.caelum.vraptor.core.DefaultRequestExecution.execute(DefaultRequestExecution.java:62)
	at br.com.caelum.vraptor.VRaptor$1.insideRequest(VRaptor.java:91)
	at br.com.caelum.vraptor.ioc.spring.SpringProvider.provideForRequest(SpringProvider.java:55)
	at br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:88)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
	at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [net.danieljurado.dialer.dao.DaoFactory] is defined: Unsatisfied dependency of type [class net.danieljurado.dialer.dao.DaoFactory]: expected at least 1 matching bean
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:613)
	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:622)
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:584)
	... 53 more

O interceptor que utiliza o bean do DaoFactory utiliza este codigo:

package net.danieljurado.dialerWeb.interceptors;

import net.danieljurado.dialer.dao.DaoFactory;
import net.danieljurado.dialerWeb.controllers.MenuController;
import br.com.caelum.vraptor.InterceptionException;
import br.com.caelum.vraptor.Intercepts;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.core.InterceptorStack;
import br.com.caelum.vraptor.interceptor.Interceptor;
import br.com.caelum.vraptor.ioc.RequestScoped;
import br.com.caelum.vraptor.resource.ResourceMethod;
import br.com.caelum.vraptor.view.Results;

@RequestScoped
@Intercepts
public class DaoFactoryInterceptor implements Interceptor {
	private final DaoFactory daoFactory;
	private final Result result;

	public DaoFactoryInterceptor(DaoFactory daoFactory, Result result) {
		super();
		this.daoFactory = daoFactory;
		this.result = result;
	}

	@Override
	public boolean accepts(ResourceMethod arg0) {
		return true;
	}

	@Override
	public void intercept(InterceptorStack stack, ResourceMethod method,
			Object instance) throws InterceptionException {
		try {
			daoFactory.beginTransaction();
			stack.next(method, instance);
			daoFactory.commit();
		} catch (Throwable e) {
			this.result.include("errors", e.getMessage());
			this.result.use(Results.logic()).redirectTo(MenuController.class)
					.menu();
		} finally {
			if (daoFactory.hasTransaction()) {
				daoFactory.rollback();
			}
			daoFactory.close();
		}
	}
}

Alguem imagina o motivo de nao estar encontrando o Resource do DaoFactory?

No web.xml acrescentei o caminho que contempla todas as packages, inclusive pras packages dentro do jar:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>dialerWeb</display-name>
  <context-param>
    <param-name>br.com.caelum.vraptor.packages</param-name>
    <param-value>net.danieljurado</param-value>
  </context-param>
  <filter>
    <filter-name>vraptor</filter-name>
    <filter-class>br.com.caelum.vraptor.VRaptor</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>vraptor</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
  </filter-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

Há um tópico onde o colega lscosta teve a mesma dúvida que você. Dê uma olhada no link http://guj.com.br/posts/list/145741.java

Abraços