gson - 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.ws.rs.Produces
为@javax.enterprise.inject.Produces
. 它现在正在工作
推荐阅读
- flutter - 如何禁用在标签栏内滑动整个屏幕?
- java - 可累加接口
- logging - 如何关闭屏幕登录?我做了一次“screen -L”,现在一个名为 screenlog.0 的文件不断生成
- r - 动态改变 ntile 的顺序
- brave - 当我单击桌面上的电话号码时,如何让 Brave 拨打我同步的电话(不是 HTML 问题)
- python - 使用 pyautogui 在 Mac 上进行屏幕录制
- python - 用 pytest-mock 模拟 sqlalchemy.order_by 不会覆盖调用
- mongodb - 如果车把上有其他变量,如何使用每个内部?
- docfx - DocFx 带有一个父子文档站点和多个单独的项目在各种 repos
- google-text-to-speech - 在 Python 中使用 Google Text-To-Speech 时,为什么会出现错误 synthesize_speech() missing 1 required positional argument: 'self'?