Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

Wiki Markup
{rate:title=Rating|theme=dynamic|key=MyPlugin}

Overview

Excerpt

该plugin提供struts的Action及Interceptor对EJB组件及Resource的无侵入式依赖注入(DI)。实现Struts2与EJB3的整合。

Usage

Please read this short info here : http://code.google.com/p/struts2-ejb3-plugin/

Example

Code Block

@Interceptors(Interceptor3.class)
public class EjbTestAction1 extends ActionSupport{

	private static final long serialVersionUID = 4126146938063764047L;

	@EJB
	private TestSessionBean1Local testSessionBean1Local;
	
	@EJB(name="ejb/sessionBean1")
	private TestSessionBean1Remote sessionBean1;
	
	private TestSessionBean1Remote session;
	
	@EJB
	public void setSession(TestSessionBean1Remote session) {
		this.session = session;
	}

	@PostConstruct
	@Interceptors({Interceptor2.class,Interceptor3.class})
	public void init(){
		//...
	}
	
	@Interceptors({Interceptor3.class,Interceptor1.class,Interceptor2.class})
	public String execute() throws Exception {
		//...
		return SUCCESS;
	}
}

在Interceptor中使用方式和在Action中的使用方式相同。

需要注意的是,在Action的execute(或者自定义的名称)方法中同时使用struts2的Interceptor和@Interceptors 时,@Interceptors会在Interceptor之前开始,在Interceptor之后结束。

Installation

将 struts2-ejb3-plugin.jar 考入 /WEB-INF/lib 目录中。这时使用的为plugin的默认配置,该配置为 cn/agrael/struts/plugin/ejb3/default-struts-ejb3-plugin.properties中的配置。配置信息如下:

Code Block
#ENC的默认名
ENCPath=java:comp/env/
#应用服务器的具体实现类,该类是 cn.agrael.struts.plugin.ejb3.ApplicationServer的实现类
ejbContainer=cn.agrael.struts.plugin.ejb3.JbossApplicationServer
#是否解析@Resource的标志 true 为解析,false 为不解析
isParseResource=false
#是否解析@EJB的标志 true 为解析,false 为不解析
isParseEJB=true
#ear的路径名,如果没有则为空字符串
earFileBaseName=
#为远程Bean时的JNDI路径
remote=remote
#为本地Bean时的JNDI路径
local=local

如果要修改默认的配置,需要在 classpath 下建立为 struts-ejb3-plugin.properties 的资源文件覆盖默认的配置。

除了plugin本身的配置以外,还需要在 classpath 下创建名为 jndi.properties 的资源文件用做 jndi配置 ,plugin 中使用到的jndi查找依赖于该配置。

目前的版本暂时不支持@PreDestroy。 现阶段只有 jboss与glassfish2.x 应用服务器的实现,在以后的版本中会陆续增加如 weblogic 等应用服务器的实现。如果现在需要 jboss与glassfish2.x之外的实现,可实现 cn.agrael.struts.plugin.ejb3.ApplicationServer 接口或者继承cn.agrael.struts.plugin.ejb3.AbstractApplicationServer类,并使用 struts-ejb3-plugin.properties 修改 ejbContainer 为实现类。
0.0.6版本开始添加了cn.agrael.struts.plugin.ejb3.annotation.ResourceComponent和cn.agrael.struts.plugin.ejb3.annotation.EJBComponent来支持自定义注解。

Resources

Version History

Version

Date

Author

Notes

0.0.1

Mar 9, 2010

Agrael Lee

Initial release

0.0.2

Mar 23, 2010

Agrael Lee

修改jar文件名为struts2-ejb3-plugin.jar,字段支持继承注解,Jboss实现的@Resource的查找在代码中补上(前一个版本有实现,但是没调用),Context现在为即时释放(close)

0.0.3

Mar 30, 2010

Agrael Lee

增加了glassfish2.x应用服务器的实现,重写了cn.agrael.struts.plugin.ejb3.JbossApplicationServer并增加一个抽象类cn.agrael.struts.plugin.ejb3.AbstractApplicationServer作为实现模版。改变对EJB注解与Resource注解的资源的查找的方式-如果当前级别属性没有找到会向更高级的属性找,而不是像0.0.2版本及之前的只在指定的最低级属性找。

0.0.4

May 10, 2010

Agrael Lee

修改了cn.agrael.util.ObjectUtils中对Class的引用为弱引用。修改了几个对象引用范围,将引用范围变小。

0.0.5

May 30, 2010

Agrael Lee

修改了plugin 内部使用的类的命名规则以及单词拼写错误。

0.0.6

Dec 22, 2011

Agrael Lee

新增了ResourceComponent和EJBComponent来支持自定义注解。