下载Jboss, quickstart, 按照quickstart说明, mvn clean install.

由于ssl handshake问题(应该是网络连接不稳定), 写了一个脚本不停地尝试build, 连续build了22次才成功.

启动jboss,注意jboss与quickstart的version要一致. 运行: mvn clean install jboss-as:deploy

注:如何查看Jboss version: standalone -v

  • HelloWorld

@WebServlet 上来就看web.xml,竟然啥也没有,原来servlet3.0定义了新的annotation. 关于用法请参见Servlet 3.0 Spec

这里用到的例子: @WebServlet("/HelloWorld") 等价于web.xml中定义的<servlet>以及<servlet-mapping>, 告诉container,加载这个url与class之间的映射。

@Inject 又一个新东西,在Servlet3.0里面搜索,啥也没有,原来是J2EE的CDI(Contexts and Dependency Injection 上下文依赖注入),如此这般。注解触角越深越多。

是J2EE哪个版本里引入的新特性呢?看来需要看一下J2EE Spec。。。请看官网link, 是J2EE6.0里的JSR330 Dependency Injection for Java 1.0

  • HelloWorld-JMS

JMS, 它需要JNDI配置,远程调用,所以需要:Jndi name。还需要添加application user,用add-user.bat添加,设置guest role即可。

运行: mvn clean compile exec:java (学到一个mvn 执行设置系统变量的小技巧,可以参见目录中pom.xml)

看了一下原代码,

先look up factory, 然后look up JMS queue, send and receive, over!

            // Perform the JNDI lookups
String connectionFactoryString = System.getProperty("connection.factory", DEFAULT_CONNECTION_FACTORY);
log.info("Attempting to acquire connection factory \"" + connectionFactoryString + "\"");
connectionFactory = (ConnectionFactory) context.lookup(connectionFactoryString);
log.info("Found connection factory \"" + connectionFactoryString + "\" in JNDI"); String destinationString = System.getProperty("destination", DEFAULT_DESTINATION);
log.info("Attempting to acquire destination \"" + destinationString + "\"");
destination = (Destination) context.lookup(destinationString);
log.info("Found destination \"" + destinationString + "\" in JNDI"); // Create the JMS connection, session, producer, and consumer
connection = connectionFactory.createConnection(System.getProperty("username", DEFAULT_USERNAME), System.getProperty("password", DEFAULT_PASSWORD));
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
producer = session.createProducer(destination);
consumer = session.createConsumer(destination);
connection.start(); int count = Integer.parseInt(System.getProperty("message.count", DEFAULT_MESSAGE_COUNT));
String content = System.getProperty("message.content", DEFAULT_MESSAGE); log.info("Sending " + count + " messages with content: " + content); // Send the specified number of messages
for (int i = 0; i < count; i++) {
message = session.createTextMessage(content);
producer.send(message);
} // Then receive the same number of messages that were sent
for (int i = 0; i < count; i++) {
message = (TextMessage) consumer.receive(5000);
log.info("Received message with content " + message.getText());
}
  • HelloWorld-MBean

有点被MBean搞晕了,到处都是注解,nd。

首先对MBean的认识有限,就是符合JMX框架规范的JavaBean,用来管理资源的,这时候我就想到为何网管不采用部署Mbean的方式呢,说白了就是get,Set一些参数,关键上层还有能对SNMP的支持。下面是我碰到的一些注解,这里面涉及到CDI概念(这里是一篇关于CDI的文章),还有EJB:

@PostConstruct  <--J2SE支持的注解(javax扩展包), The PostConstruct annotation is used on a method that needs to be executed after dependency injection is done to perform any initialization

@PreDestroy<--J2SE支持的注解(javax扩展包), The PreDestroy annotation is used on methods as a callback notification to signal that the instance is in the process of being removed by the container。

@Singleton <-- 分为 javax.ejb.Singleton, javax.inject.Singleton, 本例中为前者ejb。表明为单例,不知道该怎样使用。

@Startup   <-- javax.ejb.Startup, Mark a singleton bean for eager initialization during the application startup sequence. 何谓eager?应该就是非lazy加载方式。

@MXBean  <--JMX的annotation

看到这个代码很迷惑,注解竟然出现在参数当中,查了文档后,注解也支持parameter。但这个beforeBeanDiscovery又是个啥东西,不懂得太多了!

void beforeBeanDiscovery(@Observes BeforeBeanDiscovery beforeBeanDiscovery, BeanManager beanManager) {
        setBeanManager(beanManager);
 }

上面的代码涉及到CDI容器,容器事件监听器,@Observes注解(本例中注解表明 beforeBeanDiscovery是监听器方法,监听的事件的类型为 beforeBeanDiscovery)。

  • HelloWorld-MDB

Message Driver Bean, 10年前用过,现在又回来了,现在不用在部署描述符中写配置,只需在你的代码中写Annotation。(其实我目前很憎恶这个annotation,隐藏错误,隐藏细节,感觉很不痛快,对编程是一种破坏,给人一种支离破碎的感觉。)

@MessageDriven(name = "HelloWorldQueueMDB", activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/HELLOWORLDMDBQueue"),
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })

JBoss QuickStart之Helloworld的更多相关文章

  1. JBoss+eclipes之HelloWorld

    网上罕有教程,文档看不太懂.鄙人摸索成功以记之. 创建新的EJB项目:[File]--[New]--[Other]-- [EJB]--[EJB project] 此处可见我的JBoss服务器使用的是W ...

  2. JBoss QuickStart之深入

    EJB-AsynchronousEJB中提供异步调用的方法. "A session bean can expose methods with asynchronous client invo ...

  3. jboss上的soap web service开发示例

    以下示例,由jboss quickstart示例代码得来: 一.创建一个常规的dynamic web项目,建议支持maven ,项目的关键属性参考下图: 二.定义服务接口及参数对象 HelloWorl ...

  4. EJB之Timer

    EJB Timer 要么: Annotation @Schedule 或者方法前声明@Timeout 要么: 在部署描述中定义timeout-method 如果是使用@Schedule, Timer在 ...

  5. JAVA JPA - 示例用法

    JPA(Java Persistence API)是JSR(Java Specification Requests)的一部分,定义了一系列对象持久化的标准,目前实现这一规范的产品有Hibernate. ...

  6. Example: Develop Web application on Baidu App Engine using CherryPy

    In the past few months, I have developed two simple applications on Baidu App Engine. Compared to Go ...

  7. PHP Lavavel 使用控制器 传递变量 以及调用 视图模板

    控制器第一次入门使用 位置: 在app/Http/Controllers 目录下创建文件名格式:例如 UserController路由调用格式:Route::get('user/tom','UserC ...

  8. Go微服务框架go-kratos实战02:proto 代码生成和编码实现步骤

    在上一篇 kratos quickstart 文章中,我们直接用 kratos new 命令生成了一个项目. 这一篇来看看 kratos API 的定义和使用. 一.kratos 中 API 简介 1 ...

  9. Jboss ESB简介及开发实例

    一.Jboss ESB的简介 1. 什么是ESB.         ESB的全称是Enterprise Service Bus,即企业服务总线.ESB是过去消息中间件的发展,ESB采用了“总线”这样一 ...

随机推荐

  1. tomcat相关问题

    动态资源:需要转换成静态资源后再响应给客户端,例如:jsp.servlet,其他语言的动态资源有:asp.php 静态资源:无需转发即可直接响应给客户端,例如:html.css.javascript ...

  2. mysql 优化实例之索引创建

    mysql 优化实例之索引创建 优化前: pt-query-degist分析结果: # Query 23: 0.00 QPS, 0.00x concurrency, ID 0x78761E301CC7 ...

  3. ABAP 订单转交货单

    *& Report  ZSDR025 *& *&---------------------------------------------------------------- ...

  4. server2003中看不到网上邻居内容,其他电脑无法通过计算机名和IP访问本计算机(但网上邻居中可访问到)

    现象1:server2003中看不到网上邻居内容,查看工作组计算机看到的是空列表, 现象2:其他电脑无法通过计算机名和IP访问本计算机(但网上邻居中可访问到)   访问提示:--Windows 200 ...

  5. HTML CSS SPRITE 工具

    推荐一个CSS SPRITE工具 网盘分享:http://pan.baidu.com/s/1sjx7cZV

  6. (iOS逆向工程)class-dump 安装与使用

    class-dump,是可以把OC运行时的声明的信息导出来的工具.说白了,就是可以导出.h文件.用class-dump可以把未经加密的app的头文件导出来.废话不多说.class-dump的下载地址是 ...

  7. 四种常见的 POST 提交数据方式

    HTTP/1.1 协议规定的 HTTP 请求方法有 OPTIONS.GET.HEAD.POST.PUT.DELETE.TRACE.CONNECT 这几种.其中 POST 一般用来向服务端提交数据,本文 ...

  8. DTD文档模型和HTML基础

    html是超文本标记语言,现在常用到的2中文档格式是html5和XHTML 1.0 Transitiona(过渡). <!DOCTYPE html> <!--当前文档为html5-- ...

  9. Git TortoiseGit SSH设置

    Git TortoiseGit SSH设置 http://www.cnblogs.com/ChenRihe/p/Git_TortoiseGit_SSH.html TortoiseGit默认的SSH客户 ...

  10. XAMPP PHPSTORM XDEBUG 配合使用

    1.xdebug 配置 安装完xampp 进入 php.ini [XDebug]zend_extension = "C:\xampp\php\ext\php_xdebug.dll" ...