2
我在Apache CXF
的“how-to”阶段,想知道服务器启动时是否有方法调用方法。Apache CXF初始化的调用方法
这将是类似于JSF
Web应用程序,当我用eager=true
一个@ApplicationScoped
托管bean:当容器启动时,注释的类实例化,我可以叫我无论从它的构造需要。
任何帮助?
我在Apache CXF
的“how-to”阶段,想知道服务器启动时是否有方法调用方法。Apache CXF初始化的调用方法
这将是类似于JSF
Web应用程序,当我用eager=true
一个@ApplicationScoped
托管bean:当容器启动时,注释的类实例化,我可以叫我无论从它的构造需要。
任何帮助?
所以,如果你正在使用CXF Servlet
服务Web Service
要求,那么你就可以创建ServletContextListener
和contextInitialized
方法将被调用在部署或在服务器启动时,如果该应用程序已经部署。
要做到这一点创建类将实施ServletContextListener
:
public class YourContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
//This method is called by the container on start up
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}
然后在你的web.xml
定义监听器:
<listener>
<listener-class>your.package.YourContextListener</listener-class>
</listener>
在contextInitialized
方法,你可以通过使用获得servlet上下文:
ServletContext context = sce.getServletContext();
你可以设置尽可能多的属性可以在整个应用程序范围内使用。
Tks,它的工作!除此之外,它是一个干净而健壮的代码。 – gfernandes