Where should I open / close JMS connections in a JSF ManagedBean?

岁酱吖の 提交于 2019-12-04 11:13:01

First, move your Connection to be a instance variable so that it can be accessed from your open, close, and getMessage methods.

Next, create an openConnection method with the PostConstruct annotation.

@PostConstruct
public void openConnection() {
    connection = connectionFactory.createConnection();
}

Finally, create a closeConnection method with the PreDestroy annotation.

@PreDestroy
public void closeConnection() {
    connection.close();
}

How about in the servlet context listener?

Just define in web.xml

<listener>
  <listener-class>contextListenerClass</listener-class>
</listener>

And then implement a servletContextListener

public final class contextListenerClassimplements ServletContextListener {
...
}

Other solution can be to use SessionListener...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!