首页 > 解决方案 > WELD-001408:具有限定符 @Default 的 Gson 类型的依赖关系不满足

问题描述

我所有的其他注射都在工作,但它不适用于 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>

标签: gsoncdiweld

解决方案


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


推荐阅读