JBoss QuickStart之Helloworld
下载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的更多相关文章
- JBoss+eclipes之HelloWorld
网上罕有教程,文档看不太懂.鄙人摸索成功以记之. 创建新的EJB项目:[File]--[New]--[Other]-- [EJB]--[EJB project] 此处可见我的JBoss服务器使用的是W ...
- JBoss QuickStart之深入
EJB-AsynchronousEJB中提供异步调用的方法. "A session bean can expose methods with asynchronous client invo ...
- jboss上的soap web service开发示例
以下示例,由jboss quickstart示例代码得来: 一.创建一个常规的dynamic web项目,建议支持maven ,项目的关键属性参考下图: 二.定义服务接口及参数对象 HelloWorl ...
- EJB之Timer
EJB Timer 要么: Annotation @Schedule 或者方法前声明@Timeout 要么: 在部署描述中定义timeout-method 如果是使用@Schedule, Timer在 ...
- JAVA JPA - 示例用法
JPA(Java Persistence API)是JSR(Java Specification Requests)的一部分,定义了一系列对象持久化的标准,目前实现这一规范的产品有Hibernate. ...
- 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 ...
- PHP Lavavel 使用控制器 传递变量 以及调用 视图模板
控制器第一次入门使用 位置: 在app/Http/Controllers 目录下创建文件名格式:例如 UserController路由调用格式:Route::get('user/tom','UserC ...
- Go微服务框架go-kratos实战02:proto 代码生成和编码实现步骤
在上一篇 kratos quickstart 文章中,我们直接用 kratos new 命令生成了一个项目. 这一篇来看看 kratos API 的定义和使用. 一.kratos 中 API 简介 1 ...
- Jboss ESB简介及开发实例
一.Jboss ESB的简介 1. 什么是ESB. ESB的全称是Enterprise Service Bus,即企业服务总线.ESB是过去消息中间件的发展,ESB采用了“总线”这样一 ...
随机推荐
- LeetCode之136. Single Number
-------------------------------------- 一个数异或它自己会得到0,0异或n会得到n,所以可以用异或来消除重复项. AC代码如下: public class Sol ...
- c语言中在引用math库后,编译出现错误(.text+0x9c):对‘sqrt’未定义的引用的解决办法
写于2016年11月29日晚. 原因是gcc编译器没有引用默认的math库,需要在执行编译命令时加上-ml.例如: gcc 源文件 -ml -o 编译后文件名 或者 gcc 源文件 -lm -o 编译 ...
- <s:property value=""/> 怎么截取返回值的固定长度的字符串
------背景-------------------- 列表中某一个字段的内容较长,显示不美观的情况下可以选择使用xxxxx....来显示,具体内容可见详情. ------解决方案--------- ...
- C# 如何用多个字符串来切分字符串并去除空格
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- 基于命令行编译打包phonegap for android应用 分类: Android Phonegap 2015-05-10 10:33 73人阅读 评论(0) 收藏
也许你习惯了使用Eclipse编译和打包Android应用.不过,对于使用html5+js开发的phonegap应用,本文建议你抛弃Eclipse,改为使用命令行模式,绝对的快速和方便. 一直以来,E ...
- 基于hk2框架的功能测试Mock注入
public Object getInstance(Class<?> clz){ return IocBean.get(clz.getName()); } public Object Mo ...
- Python学习笔记(三)——类型与变量
一.输入与输出 print("string"); print("string1","string2","string3" ...
- Java代码常用写法总结
1.字符串是否为空判断 以下是java 判断字符串是否为空的四种方法:方法一: 最多人使用的一个方法, 直观, 方便, 但效率很低: if(s == null ||"".equal ...
- 首师大附中互测题:99999999海岛帝国后传:算法大会【D001】
[D001]99999999海岛帝国后传:算法大会[难度:D] ———————————————————————————————————————————————————————————————————— ...
- LightOJ1171 Knights in Chessboard (II)(二分图最大点独立集)
题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1171 Description Given an m x n ches ...