类“ com.company.project.controller.Diccionario $ Proxy $ _ $$ _ Weld $ EnterpriseProxy $”

时间:2018-09-25 19:14:21

标签: java dependency-injection

我在依赖注入方面遇到了麻烦,当一切顺利时,它可以很好地工作。当发生异常时,我捕获它并检查对象方法,当我这样做时,可检查器会显示标题中描述的消息:

There is no method "get" in class "com.company.project.controller.Diccionario$Proxy$_$$_Weld$EnterpriseProxy$"

如果我继续执行该程序,则会在控制台上抛出异常:

javax.ejb.TransactionRolledbackLocalException: Client's transaction aborted

提前感谢所有回复!

这是我的相关代码:

通用控制器

<!-- language: lang-java -->
public abstract class Controller<C> {

    @Inject
    protected Diccionario texto;

    public List<String> save(C entidad) {
    List<String> res = new ArrayList();
        try {
            getDao().save(entidad); // <-- here I can inspect texto.get("test");
        } catch (UniqueException ex) {
            String key = "test";
            String value = texto.get(key); // <-- here it shows the "There is no method..."
            res.add(value);
        }
        return res;
    }
}

使用通用控制器的控制器

<!-- language: lang-java -->
@Stateless
public class ControllerProducto extends Controller<Producto> {

}

Diccionario类:

<!-- language: lang-java -->
@Stateless
public class Diccionario {

    private HashMap<String, String> etiquetas;

    private void init() {
        etiquetas = new HashMap();
        etiquetas.put("test", "This is a sample test");
    }

    public String get(String clave) {
        if (etiquetas == null) {
            init();
        }
        String res = "";
        if (etiquetas.containsKey(clave.toUpperCase())) {
            res = etiquetas.get(clave);
        }
        return res;
    }
}

0 个答案:

没有答案