【问题标题】:WELD-001408: Unsatisfied dependencies for type Gson with qualifiers @DefaultWELD-001408:具有限定符 @Default 的 Gson 类型的依赖关系不满足
【发布时间】:2018-12-19 10:28:01
【问题描述】:

我所有的其他注入都在工作,但它不适用于 gson。我觉得这是因为它是一个外部包,但我无法解决这个问题。这是我的相关文件:

制作人:

public class GsonFactory {
    @Produces
    public Gson createGson(){return new GsonBuilder().createGson();}
}

注入点:

@ApplicationScoped
public class SoundcloudAPIWrapper implements Serializable{

    @Inject
    private Gson gson;

    public SoundcloudAPIWrapper() {}

    ...

}

Beans.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
    bean-discovery-mode="all" version="2.0">
</beans>

【问题讨论】:

  • 你能确认@Produces不是@javax.ws.rs.Produces,而是@javax.enterprise.inject.Produces
  • 那么用String替换Gson就可以了?
  • 谢谢你是企业@javax.enterprise.inject.Produces。现在它正在工作。但是为什么@javax.ws.rs.Produces 不起作用?我所有的其他工厂都使用 ws.rs 。我对javaee很陌生,所以解释会很好:)

标签: gson cdi weld


【解决方案1】:

就像@maress 在评论中指出的那样,我需要用@javax.enterprise.inject.Produces 替换@javax.ws.rs.Produces。它现在正在工作

【讨论】:

    猜你喜欢
    • 2015-06-10
    • 2015-04-05
    • 2014-12-20
    • 2017-08-28
    • 1970-01-01
    • 1970-01-01
    • 2015-05-08
    • 1970-01-01
    • 2015-02-09
    相关资源
    最近更新 更多