ejb3.0的嵌入式开发

我最近在学习EJB3.0,在利用ejb3.0进行嵌入开发的时候出现了异常

实体bean:person.java

packagecom.shen;

importjavax.persistence.Entity;

importjavax.persistence.GenerationType;

importjavax.persistence.GeneratedValue;

importjavax.persistence.Id;

importjavax.persistence.Column;

importjavax.persistence.Table;

importjava.io.Serializable;

@Entity

@Table(name="person")

publicclassPersonimplementsSerializable{

privateintid;

privateStringname;

privateintage;

privateStringaddress;

@Column(name="paddress")

publicStringgetAddress(){

returnaddress;

}

publicvoidsetAddress(Stringaddress){

this.address=address;

}

@Column(name="page")

publicintgetAge(){

returnage;

}

publicvoidsetAge(intage){

this.age=age;

}

@Id

@Column(name="pid")

@GeneratedValue(strategy=GenerationType.AUTO)

publicintgetId(){

returnid;

}

publicvoidsetId(intid){

this.id=id;

}

@Column(name="pname")

publicStringgetName(){

returnname;

}

publicvoidsetName(Stringname){

this.name=name;

}

}

会话bean:Access.java和AccessBeanRemote.java

packagecom.shen;

importjavax.ejb.Remote;

@Remote

publicinterfaceAccess{

publicintcreate(Personperson);

publicPersonfindById(intkey);

}

packagecom.shen;

importjavax.persistence.EntityManager;

importjavax.ejb.Stateless;

importcom.shen.Access;

importjavax.persistence.PersistenceContext;

public@StatelessclassAccessBeanRemoteimplementsAccess{

@PersistenceContext

privateEntityManagermanager;

//获得某个类的主键ID

publicintcreate(Personperson){

manager.persist(person);

returnperson.getId();

}

//获得某个类

publicPersonfindById(intkey){

Personperson=manager.find(Person.class,key);

returnperson;

}

}

persistence.xml

<?xmlversion="1.0"encoding="UTF-8"?>

<persistence>

<persistence-unitname="Person">

<jta-data-source>

java:/DefaultDS

</jta-data-source>

<propertiesname="hibernate.hbm2ddl.auto"value="create-drop">

</properties>

</persistence-unit>

</persistence>

我根据要求添加了jboss的嵌入式的开发包jboss-EJB-3.0_Embeddable_ALPHA_9中conf和lib下的文件

客户端代码:

/**

*

*/

packagecom.client;

importorg.jboss.ejb3.embedded.EJB3StandaloneBootstrap;

importcom.shen.*;

importjavax.naming.InitialContext;

/**

*@authorfjshenhq

*

*/

publicclassClient{

/**

*@paramargs

*/

publicstaticvoidmain(String[]args){

try{

//开发EJB3.0嵌入式

EJB3StandaloneBootstrap.boot(null);

EJB3StandaloneBootstrap.scanClasspath();

InitialContextict=newInitialContext();

Accessaccess=(Access)ict.lookup("AccessBeanRemote/remote");

Personperson=newPerson();

person.setName("shenhuoqin");

person.setAge(25);

person.setAddress("fujiansheng");

intkey=access.create(person);

Personp=access.findById(key);

System.out.println("=========="+p.getId());

System.out.println("=========="+p.getName());

System.out.println("=========="+p.getAge());

System.out.println("=========="+p.getAddress());

}catch(Exceptione){

e.printStackTrace();

}

}

}

我运行客户端代码的时候,就报出异常啊!

java.lang.RuntimeException:java.lang.RuntimeException:Cannotfindembedded-jboss-beans.xml

atorg.jboss.ejb3.embedded.EJB3StandaloneBootstrap.boot(EJB3StandaloneBootstrap.java:386)

atcom.client.Client.main(Client.java:22)

Causedby:java.lang.RuntimeException:Cannotfindembedded-jboss-beans.xml

atorg.jboss.ejb3.embedded.EJB3StandaloneBootstrap.boot(EJB3StandaloneBootstrap.java:372)

...1more

找不到embedded-jboss-beans.xml,但是我已经把这个文件加在里面啊,为什么它会说找不到?

相关推荐