本文介绍了带有限定符@Bundle的ResourceBundle类型的依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 基于建议的解决方案此处,我正在尝试使用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@SessionScopedpublic 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请提供任何帮助。推荐答案 这篇文章帮助我更正和运行了代码,没有任何其他异常This post helped me to correct and run the code without any further Exception@[email protected]("com.locale.admin.user")private transient ResourceBundle uiResources;通过瞬变到ResourceBundle。 非常感谢SiliarusWith transient to ResourceBundle.Thanks a lot @Siliarus 这篇关于带有限定符@Bundle的ResourceBundle类型的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-10 16:52