下载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. ASP.NET获取客户端的相关信息

    /// <summary>        /// 获取远程浏览器端 IP 地址        /// </summary>        /// <returns> ...

  2. 15.django之Django-Rest-Framework

    1.首先安装Django-Rest-Framework pip3 install djangorestframework pip3 install markdown Markdown为可视化 API ...

  3. ubuntu 创建用户

    http://www.jb51.net/article/45848.htm  创建用户

  4. PHP-----练习-------租房子-----增删改查,多条件查询

    练习-------租房子-----增删改查,多条件 一 .题目要求: 二 .做法: [1]建立数据库 [2]封装类文件------DBDA.class.php <?php class DBDA ...

  5. c/c++连接mysql数据库

    环境:win7 x64.vs2008.mysql 对于已经安装mysql的,查看mysql安装目录,如果安装目录下没有include和lib目录, 说明没有完全安装,需要下载mysql-connect ...

  6. Designing IP-Based Video Conferencing Systems: Dealing with Lip Synchronization(唇音同步)

    转自:http://www.ciscopress.com/articles/article.asp?p=705533&seqNum=6 Correlating Timebases Using ...

  7. fabric devenv Vagrantfile配置

    Vagrantfile文件只会在第一次执行vagrant up时调用执行,其后如果不明确使用vagrant reload,则不会被强制重新加载. # This is the mount point f ...

  8. Excel word “由于本机的限制_该操作已被取消_请与管理员联系”的已生效解决办法 (转 )

    正常解决方法: 1.打开开始菜单,在运行里输入regedit,回车 2.在注册表中,导航到HKEY_CURRENT_USER\Software\Classes\.html 项 3.在默认项上点右键选择 ...

  9. Light oj1031 Easy Game (区间dp)

    题目链接:http://vjudge.net/contest/140891#problem/F A和B都足够聪明,只有我傻,想了好久才把代码和题意对应上[大哭] 代码: #include<ios ...

  10. npm-bluebird使用

    API 注意 时刻注意return; 使用Promise.promisify简化对test(val, function(err, result){})的处理; 尽量避免使用deferred objec ...