有关JEE6 CDI setup

简单看了一下,说是必须有一个配置文件beans.xml,但该文件可以是完全空白的。why?!

如果部署到.war而没有用到ejb,则可将该文件打包到WEB-INF。如果用到了ejb,则应该放到META-INF底下。

CDI 主要的annotation 有@Named, @Inject,还有些scope等。

测试结果,JBOSS6.1 对@Named的支持有问题,好像表单绑定不上呵!@Inject还行吧。

希望JBOSS7能改善,可JBOSS7的目录结构全改了,这些亡八蛋们,不就是为了出书挣点钱吗?奥,还有support

A JEE6 CDI test class. Can be accessed with EL #{ct.welcome}
package com.jxee.cdi.tst;

import java.io.Serializable;
import javax.inject.Inject;
import org.apache.log4j.Logger;

/**
 * to enable CDI, a "beans.xml" must be present. it could be "completely" empty.
 * <br/>
 * it can either be packaged under WEB-INF/beans.xml for a web application;
 * or be packaged under META-INF/beans.xml if EJBs are used.  
 * <br/>
 * since we used EJB in the example, it needs to be put under META-INF.
 */
@javax.inject.Named("ct")
@javax.enterprise.context.SessionScoped 
public class CDITester implements Serializable {

  private static final Logger log = Logger.getLogger(CDITester.class);
  private String welcome = "Very warm welcome (-; ";
  
  //@Inject Object anyObjectUneed2Inject;

  public String getWelcome() {
    log.debug("u saw me, since CDI is working!");
    return welcome;
  }
}


小姐一下:

JEE6 CDI 配置很简单,但至少JBOSS6.1支持不得力。目前看来还是forget it,以后再说。简简单单的,比什么都强。技术是为人服务的,人不能被技术淹死。

你可能感兴趣的:(CDI,Beans.xml,JEE6,@Named,@Inject)