我在项目中使用 JBoss EAP 6.4.10,并且我已经使用 @Startup
设置了 @Singleton
。这个单例被 @Inject
编辑到 @Interceptor
中,因为我在拦截器中使用了它的一些方法。
到目前为止,它基本上可以工作,但我注意到,@Singleton
的 @PostConstruct
方法不是被调用一次,而是被调用了 496 次。所以我想知道为什么会发生这种情况。我不能在拦截器中注入(inject)单例吗?
最佳答案
我发现了问题所在。我导入了 import javax.ejb.Singleton;
而不是 import javax.inject.Singleton;
关于java - 单例注入(inject)拦截器多个实例化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40528661/