Jboss有一个扩展的annotation——@Service。被加了这个annotation的bean就变成server里面的一个单例bean。所有请求该bean资源的client获得到的是同一个实例。
@Service的bean出了支持@Local 和@Remote外,还支持使用@Management来管理它的生命周期。使用方法如下:
一. 创建一个接口
二. 创建一个@Service的bean
加了@Management以后,该bean自动成为一个MBean,在JMXConsole里面就可以找到对应的管理方法。
容器自动会load这个类,而且会自动调用create()和start()。在关闭的时候会自动调用stop()和destroy()。
@Service的bean出了支持@Local 和@Remote外,还支持使用@Management来管理它的生命周期。使用方法如下:
一. 创建一个接口
package org.jboss.tutorial.service.bean;
import org.jboss.annotation.ejb.Management;
public interface ServiceOneManagement
{
void create() throws Exception;
void start() throws Exception;
void stop();
void destroy();
//other method
} |
二. 创建一个@Service的bean
package org.jboss.tutorial.service.bean;
import org.test.OtherServiceManagement;
import javax.ejb.Remote;
import org.jboss.annotation.ejb.Service;
import org.jboss.annotation.ejb.Depends;
@Service
@Management(ServiceOneManagement.class)
public class ServiceOne implements ServiceOneManagement
{
// Lifecycle methods
public void create() throws Exception
{
System.out.println("ServiceOne - Creating");
}
public void start() throws Exception
{
System.out.println("ServiceOne - Starting");
}
public void stop()
{
System.out.println("ServiceOne - Stopping");
}
public void destroy()
{
System.out.println("ServiceOne - Destroying");
}
} |
加了@Management以后,该bean自动成为一个MBean,在JMXConsole里面就可以找到对应的管理方法。
容器自动会load这个类,而且会自动调用create()和start()。在关闭的时候会自动调用stop()和destroy()。
最后
以上就是秀丽萝莉最近收集整理的关于Jboss @Service的使用的全部内容,更多相关Jboss内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复