在Apache CXF initialiaze调用方法 [英] Call method on Apache CXF initialiaze

查看:236
本文介绍了在Apache CXF initialiaze调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在如何做相的Apache CXF ,并想知道是否有一种方法来调用一个方法在服务器启动时。

I'm in the "how-to" phase with Apache CXF and would like to know if there's a way to call a method when the server is started.

这将是类似于 JSF Web应用程序,当我使用 @ApplicationScoped 托管bean与渴望= TRUE :当容器启动时,注解的类实例化,我可以叫我无论从它的构造要

It would be similar to a JSF web application, when I use a @ApplicationScoped managed bean with eager=true: when the container is started, the annotated class is instantiated and I can call whatever I want from its constructor.

任何帮助吗?

推荐答案

所以,如果你使用 CXF的Servlet 服务 Web服务要求,那么你可以创建的ServletContextListener contextInitialized 方法将被要求部署或在服务器启动了,如果应用程序已经部署。

So, If you are using CXF Servlet to serve Web Service request, then you can create ServletContextListener and contextInitialized method will be called on deployment or on server start up if the application is already deployed.

要做到这一点创建类将实施的ServletContextListener

To do that create class which will implement 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上下文:

In the contextInitialized method you can get servlet context by using:

ServletContext context = sce.getServletContext();

和你想成为可用到整个应用范围可以设置尽可能多的属性。

And you can set as many attributes as you want to be available into whole application scope.

这篇关于在Apache CXF initialiaze调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆