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>

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

最新更新