Jordi
Jordi

Reputation: 23197

Arquillian over Wildfly DeploymentException: WELD-001408: Unsatisfied dependencies

I've a very simple test:

@RunWith(Arquillian.class)
public class SimpleTest
{
    
    @Inject private SingleEntity singleEntity;
    
    @Deployment
    public static WebArchive createDeployment()
    {   
        return ShrinkWrap.create(WebArchive.class)
            .addClass(SingleEntity.class)
            .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
    }
    
    @Test
    public void categorize()
    {
        assertNotNull(this.singleEntity);
    }
}

I only want to inject a object of type SingleEntity. SingleEntity is a single POJO:

public class SingleEntity
{
    private String id;
    private String description;
    
    public SingleEntity(String id, String description) {
        super();
        this.id = id;
        this.description = description;
    }

    //getters & setters
}

After, that I perform gradle test. I've configured tests in order for Arquillian to perform them in a Wildfly embedded instance:

<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">  
  
    <container qualifier="jboss" default="true">  
        <configuration>  
        <!-- Supported property names: [managementPort, username, managementAddress, bundlePath, managementProtocol,   
                    cleanServerBaseDir, jbossHome, password, modulePath] -->  
            <property name="jbossHome">C:\servers\wildfly-Test-8.2.0.Final</property>
            <property name="modulePath">C:\servers\wildfly-Test-8.2.0.Final\modules\</property>
            <!-- <property name="managementPort">8888</property> -->  
        </configuration>  
    </container>  
</arquillian>  

It's very straightforward, however, I receive a exception telling me SingleEntity cann't be resolved:

Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type SingleEntity with qualifiers @Default

at injection point [BackedAnnotatedField] @Inject private com.jeusdi.arquillian.SimpleTest.singleEntity

at com.jeusdi.arquillian.SimpleTest.singleEntity(SimpleTest.java:0)

Any ideas? Thanks for all

Upvotes: 1

Views: 1534

Answers (1)

John Ament
John Ament

Reputation: 11723

In general, you don't want to inject entities. JPA is based on class names, and CDI uses proxies instead of concrete classes. This results in different classes being injected.

Now that's only best practice. You'll probably still run into other errors if you try moving forward, but you shouldn't get this error if everything's correct.

Your entity has no bean defining annotations. If you're using CDI 1.2 (which wildfly 8.2 provides), and your beans.xml doesn't explicitly list out bean-discovery-mode=all then this entity won't be picked up.

Upvotes: 2

Related Questions