我是靠谱客的博主 秀丽萝莉,这篇文章主要介绍Jboss @Service的使用,现在分享给大家,希望可以做个参考。

Jboss有一个扩展的annotation——@Service。被加了这个annotation的bean就变成server里面的一个单例bean。所有请求该bean资源的client获得到的是同一个实例。
@Service的bean出了支持@Local 和@Remote外,还支持使用@Management来管理它的生命周期。使用方法如下:
一. 创建一个接口
 
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
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
 
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(66)

评论列表共有 0 条评论

立即
投稿
返回
顶部