是否可以为注入 @Named bean 的所有对话对象全局设置对话超时?
我有几个 @ConversationScoped bean,例如:
import javax.annotation.PostConstruct;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;
@Named
@ConversationScoped
public class SomeBean1 {
@Inject
private Conversation conversation;
@PostConstruct
private void init() {
if (conversation.isTransient()) {
conversation.begin();
}
}
}
@Named
@ConversationScoped
public class SomeBean2 {
@Inject
private Conversation conversation;
@PostConstruct
private void init() {
if (conversation.isTransient()) {
conversation.begin();
}
}
}
这些对话的默认超时为 600000 毫秒。我想知道是否有任何方法可以全局设置对话超时,或者我需要在每个 bean 中设置它
if (!conversation.isTrainsient()) {
conversation.setTimeout(MY_CUSTOM_TIMEOUT);
}
(问题是有很多 CDI bean 并且在每个中手动设置超时不是最好的解决方案)