简体   繁体   English

WELD-001408:在注入点 [BackedAnnotatedField] @Inject 带有限定符 @Default 的 UserService 类型的依赖项不满足

[英]WELD-001408: Unsatisfied dependencies for type UserService with qualifiers @Default at injection point [BackedAnnotatedField] @Inject

I get an error while @Inject . @Inject出现错误。 I don't understand why.我不明白为什么。

My Application Server: GlassFish 4.1.2我的应用服务器:GlassFish 4.1.2

The server gives an error when I @Inject my Class I created当我@Inject我创建的类时,服务器出现错误

java.io.IOException: com.sun.enterprise.admin.remote.RemoteFailureException: Error occurred during deployment: Exception while loading the app : CDI deployment failure:WELD-001408: Unsatisfied dependencies for type UserService with qualifiers @Default at injection point [BackedAnnotatedField] @Inject private jobs.SignUpCDIB.userServiceat jobs.SignUpCDIB.userService(SignUpCDIB.java:0)

The server gives an error when I @Inject my Class I created当我 @Inject 我创建的类时,服务器出现错误

package jobs;

import services.UserService;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;

@Named
@ConversationScoped
public class SignUpCDIB implements Serializable {

    private static final long serialVersionUID = 1L;

    @Inject
    private UserService userService;
}

I'm trying to inject it to another class like:我正在尝试将其注入另一个类,例如:

package services;

import jobs.User;

public interface UserService {

    void save(User user);
}

UserService implement java class UserService 实现java类

package services;

import jobs.User;

import java.io.Serializable;

public class UserServiceImpl implements UserService, Serializable {
    @Override
    public void save(User user) {

    }
}

Maven pom xml file Maven pom xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>loginTutorials1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.2.13</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.13</version>
        </dependency>

        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
        </dependency>
    </dependencies>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>```


The reason why you're getting this error is evident from the error message produced by the DI container.从 DI 容器生成的错误消息可以明显看出您收到此错误的原因。 As you can see by this:正如你所看到的:

Unsatisfied dependencies for type UserService with qualifiers @Default at injection point

The container notifies you that there is no bean eligible for injection for the requested implementation (ie UserService is this case).容器会通知您,对于所请求的实现,没有符合注入条件的 bean(即UserService就是这种情况)。

Adding the @Singleton annotation makes this visible to the DI container and at the same time automatically eligible for injection.添加@Singleton注释使其对 DI 容器可见,同时自动符合注入条件。

The annotation in question work pretty much in the same way as the @ConversationScoped you have on your other class, albeit with a few differences in the scope of which the bean is available.有问题的注释的工作方式与您在其他类上的@ConversationScoped几乎相同,尽管在 bean 可用的范围上有一些差异。

I suggest you do a good read up on how bean and DI is handled in general.我建议您仔细阅读 bean 和 DI 的一般处理方式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WELD-001408:在注入点 [BackedAnnotatedField] @Inject 具有限定符 @Default 的类型 Logger 的依赖关系不满足 - WELD-001408: Unsatisfied dependencies for type Logger with qualifiers @Default at injection point [BackedAnnotatedField] @Inject DeploymentException: WELD-001408: 不满意的类型依赖<Class>在注入点使用限定符 @Default [BackedAnnotatedField] - DeploymentException: WELD-001408: Unsatisfied dependencies for type <Class> with qualifiers @Default at injection point [BackedAnnotatedField] WELD-001408类型的不满意依赖关系...在注入点使用限定符[@Default] - WELD-001408 Unsatisfied dependencies for type … with qualifiers [@Default] at injection point DeploymentException:WELD-001408:带有限定符@Default的类型[]的不满意依赖项 - DeploymentException: WELD-001408: Unsatisfied dependencies for type [] with qualifiers @Default WELD-001408:带限定符@Default的ServiceLocator类型的依赖关系未满足 - WELD-001408: Unsatisfied dependencies for type ServiceLocator with qualifiers @Default WELD-001408:带限定符@Default的类型验证器的依赖关系不令人满意 - WELD-001408: Unsatisfied dependencies for type Validator with qualifiers @Default WELD-001408:带有限定符 @Default 的类型 Logger 的依赖关系不满足 - WELD-001408: Unsatisfied dependencies for type Logger with qualifiers @Default Java Web Injection(Vraptor)+ Websphere 8.5:WELD-001408:带有限定符@Default的EntityManager类型的依赖关系未得到满足 - Java Web Injection (Vraptor) + Websphere 8.5: WELD-001408: Unsatisfied dependencies for type EntityManager with qualifiers @Default 在注入点 [BackedAnnotatedField] @Inject &quot;Implementation&quot; 带有限定符 @Default 的类型“接口”的不满意依赖项 - Unsatisfied dependencies for type "Interface" with qualifiers @Default at injection point [BackedAnnotatedField] @Inject "Implementation" Java EE CDI部署异常-WELD-001408:带有限定符@Default的EntityManager类型的依赖关系未满足 - Java EE CDI Deployment Exception - WELD-001408: Unsatisfied dependencies for type EntityManager with qualifiers @Default
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM