Arquillian nao injeta dependencia

2 respostas
B

PEssoal, estou tentando utilizar o arquillian, mas estou com o seguinte problema:

@RunWith(Arquillian.class)
public class ContratoJpaRepositoryTest {

    @Deployment
    public static Archive<?> deployment() throws IllegalArgumentException, FileNotFoundException {

        WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")
                .addClasses(IRepository.class, ContratoJpaRepositoryTest.class)
                .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"))
                .addAsWebInfResource("test-persistence.xml" ,ArchivePaths.create("persistence.xml"));
        
        return war;
        
    }

    @Inject
    private TodosContratos todosContratos;

    @Test
    public void buscaPorFiltroEspecificandoNumero() throws Exception {
        // given
        Contrato exemplo = new Contrato();
        exemplo.setNumero(1);

       // when
        List<Contrato> encontrados = todosContratos.buscaPorFiltro(exemplo, null, null);

        // then
        Assert.assertEquals(1, encontrados.size());
    }

Arquillian.xml

<arquillian xmlns="http://jboss.org/schema/arquillian"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="
        http://jboss.org/schema/arquillian
        http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
	<defaultProtocol type="Servlet 3.0" />
</arquillian>
6:21:18,264 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC00001: Failed to start service jboss.deployment.unit."test.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."test.war".WeldService: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [EntityManager] with qualifiers [@Default] at injection point [[field] @Inject protected br.com.sistema.repositories.jpa.JpaRepository.entityManager]
	at org.jboss.as.weld.services.WeldService.start(WeldService.java:83)
	at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
	at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_32]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_32]
	at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_32]
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [EntityManager] with qualifiers [@Default] at injection point [[field] @Inject protected br.com.sistema.repositories.jpa.JpaRepository.entityManager]
	at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:275)
	at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:244)
	at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:107)
	at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:127)
	at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:346)
	at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:331)
	at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:366)
	at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:83)
	at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)
	... 5 more

16:21:18,475 INFO  [org.jboss.as.server] (management-handler-thread - 2) JBAS015870: Deploy of deployment "test.war" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"test.war\".WeldService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"test.war\".WeldService: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [EntityManager] with qualifiers [@Default] at injection point [[field] @Inject protected br.com.sistema.repositories.jpa.JpaRepository.entityManager]"}}
16:21:18,552 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015877: Stopped deployment test.war in 77ms
16:21:18,554 INFO  [org.jboss.as.controller] (management-handler-thread - 2) JBAS014774: Service status report
JBAS014777:   Services which failed to start:      service jboss.deployment.unit."test.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."test.war".WeldService: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [EntityManager] with qualifiers [@Default] at injection point [[field] @Inject protected br.com.sistema.repositories.jpa.JpaRepository.entityManager]

Alguem tem alguma ideia do que pode estar acontecendo ???

Obrigado…

2 Respostas

R

Como esta a seu EntityManagerfactory? Pelo erro vc não tem o @Produces no EntityManager para poder instaciar seus beans,

Vc já subiu a aplicação ou ainda esta só nos testes? Tente subir a aplicação e verá que o erro ainda persiste

B

Realmente estava faltando um @Produces

Obrigado Rafael !!

Criado 10 de julho de 2012
Ultima resposta 11 de jul. de 2012
Respostas 2
Participantes 2