在CDI中有@ApplicationScoped
和(javax.inject
)@Singleton
伪范围.他们之间有什么区别?除了@ApplicationScoped
代理的事实,而@Singleton
不是.
我可以把我的@Singleton
豆子改成@ApplicationScoped
吗?可@ApplicationScoped
豆有两个(或更多)的实例?
我需要获得一些配置并连接到某处的外部资源/对象/系统并将其存储在应用程序范围内.
我可以看到两种设置应用程序的方法:
init()
现有的servlet和所需的代码,并将所有构造的对象保留在同一个servlet中.init()
来完成工作.然后存储创建的对象ServletContext
以与其他servlet共享.以上哪种方法更好?有没有更好的方法在servlet之间共享对象?直接从彼此调用它们......?
I'm building a JSF+Facelets web app, one piece of which is a method that scans a directory every so often and indexes any changes. This method is part of a bean which is in application scope. I have built a subclass of TimerTask to call the method every X milliseconds. My problem is getting the bean initialized. I can reference the bean on a page, and when I go to the page, the bean is initialized, and works as directed; …
我想知道,以下两者之间的主要区别是什么:
我知道@SessionScoped和@Stateful允许为每个客户端创建一个新实例.我也知道,对于@ApplicationScoped和@Singleton/@Stateless,它们在客户端之间共享.
但是,我什么时候应该考虑选择一个EJB或另一个更好?