带有限定符@Bundle的ResourceBundle类型的依赖关系 [英] Unsatisfied dependencies for type ResourceBundle with qualifiers @Bundle

查看:101
本文介绍了带有限定符@Bundle的ResourceBundle类型的依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于建议的解决方案此处,我正在尝试使用CDI @Produces以便能够通过@Inject访问多个属性文件:

Based on the proposed solution here, I am trying to use CDI @Produces to be able to access with @Inject multiple properties files:

捆绑界面

package com.locale;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.enterprise.util.Nonbinding;
import javax.inject.Qualifier;

@Qualifier
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface Bundle {

    @Nonbinding
    public String value() default "";
}

BundleProducer类

package com.locale;

import java.io.Serializable;
import java.util.ResourceBundle;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;

public class BundleProducer implements Serializable{

    @Produces
    @Bundle
    public ResourceBundle loadBundle(InjectionPoint ip) {
        String bundleName = ip.getAnnotated().getAnnotation(Bundle.class).value();
        ResourceBundle res = ResourceBundle.getBundle(bundleName);
        return res;
    }
}

我在其中注入捆绑软件的类:

@Named
@SessionScoped
public class PasswordBean implements Serializable {

    @Inject @Bundle("com.locale.admin.user")
    private ResourceBundle uiResources;

    public String chgPassword() {
        if (currentPwd isNotOk) {
            FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR, uiResources.getString("cpwdIncorrect"), "");
            ctx.addMessage(null, fm);
            return null;
        }
    }
}

例外:

Exception while loading the app : CDI deployment failure:WELD-001408: Unsatisfied dependencies for type ResourceBundle with qualifiers @Bundle
  at injection point [BackedAnnotatedField] @Inject @Bundle private com.security.PasswordBean.uiResources
  at com.security.PasswordBean.uiResources(PasswordBean.java:0)
org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type ResourceBundle with qualifiers @Bundle
  at injection point [BackedAnnotatedField] @Inject @Bundle private com.security.PasswordBean.uiResources

请提供任何帮助。

推荐答案

< a href = https://stackoverflow.com/a/3270570/1227941>这篇文章帮助我更正和运行了代码,没有任何其他异常

This post helped me to correct and run the code without any further Exception

@Inject
@com.locale.Bundle("com.locale.admin.user")
private transient ResourceBundle uiResources;

通过瞬变到ResourceBundle。
非常感谢Siliarus

With transient to ResourceBundle. Thanks a lot @Siliarus

这篇关于带有限定符@Bundle的ResourceBundle类型的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆