jsf faces Inject 在部署到 wildfly 时无法正常工作

jsf faces Inject not working while deploying to wildfly

我在我的项目中使用 JPA ecilpse link。以下是我的 pom.xml

<groupId>sms</groupId>
<artifactId>sms</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<dependencies>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.5.0</version>
    </dependency>

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>3.0.4.Final</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
    </dependency>

    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-apt</artifactId>
        <version>3.0.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-jpa</artifactId>
        <version>3.0.0</version>
    </dependency>

    <dependency>
        <groupId>javax.ejb</groupId>
        <artifactId>javax.ejb-api</artifactId>
        <version>3.2</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.faces</groupId>
        <artifactId>javax.faces-api</artifactId>
        <version>2.2</version>
    </dependency>


</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>

        <plugin>
            <groupId>com.mysema.maven</groupId>
            <artifactId>apt-maven-plugin</artifactId>
            <version>1.0.9</version>
            <executions>
                <execution>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>target/generated-sources/java</outputDirectory>
                        <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我创建了一个数据访问 class 如下

@RequestScoped
public class AddressDao extends BaseDao<Address, QAddress>{
}

以下是我的资源文件。

@Path("hello")
@RequestScoped
@Stateless
public class StructureResource {

    @Inject
    AddressDao addressDao;

    @GET
    public Response getList(){
       Address address = addressDao.get(1L);
       return Response.ok().build();
    } 
}

部署时出现以下错误。

Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type AddressDao with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject     com.sms.modules.identity.boundary.StructureResource.addressDao

请让我知道我缺少的东西是什么。

你是否在你的maven项目的resources目录中创建了文件beans.xml?它是 CDI 规范所要求的,用于标记 AS 容器将在其中查找 CDI bean 的罐子。