一、配置Eclipse与MyEclipse
省略:去网上找相关资料
二、配置Weblogic8.1
省略:去网上找相关资料
三、配置Weblogic8.1的数据源
- 启动Weblogic服务器,打开weblogic的后台管理器(http://127.0.0.1:7001/console)
- 配置Connection Pools,位置:右边菜单树mydomain--Services--JDBC--Connection Pools
- 配置完Connection Pools后,配置DataSources,位置:右边菜单树mydomain--Services--JDBC-DataSources
- 记住所配置的DataSources的名字,切记所配置的数据源中的数据库是将来配置Entity Bean时能访问到的表。
四、新建Entity Bean
- 新建EJB工程。因为是Weblogic8.1所以在选择J2EE版本一定要选择1.3否则就重新建吧
- 新建Entity Bean。其中包名需要是ejb结尾,否则MyEclipse会warning的。其它设置随便。在选择EJB类型时选择CMP2.X,选择EJB访问形式时,选择both
- 编辑Entity Bean由于MyEclipse生成的Entity Bean有些设置还没有完全设置好所以需要重新设置
/***//**
*XDoclet-basedCMP2.xentitybean.Thisclassmustbedeclared
*publicabstractbecausetheconcreteclasswill
*beimplementedbytheCMPproviderstooling.
*
*TogenerateEJBrelatedclassesusingXDoclet:
*
*-AddStandardEJBmoduletoXDocletprojectproperties
*-CustomizeXDocletconfiguration
*-RunXDoclet
*
*Belowarethexdoclet-relatedtagsneededforthisEJB.
*
*@ejb.beanname="Role" //你的Entity Bean的名字
display-name="Role" //在生成ejb-jar.xml时的displayname
description="Role"
*jndi-name="ejb/Role" //远程访问该EJB是的JNDI名字,这个在调用的时候需要的
type="CMP" //该Entity Bean的类型
cmp-version="2.x" //CMP的版本
view-type="both" //访问该EJB的形式,both表示Local和Remote都支持
primkey-field="roleId" //在连接数据表时的主键字段
@ejb.persistencetable-name="ROLE" //在连接数据库时数据表名,必须是数据库中名字
ejb:util
*generate="physical"
*/
publicabstractclassRoleimplementsEntityBean...{
/***//**Theentitycontext*/
privateEntityContextcontext;
publicRole()...{
//TODOAuto-generatedconstructorstub
}
/***//**
*TherearezeroormoreejbCreate<METHOD>(...)methods,whosesignaturesmatch
*thesignaturesofthecreate<METHOD>(...)methodsoftheentitybean?shomeinterface.
*ThecontainerinvokesanejbCreate<METHOD>(...)methodonanentitybeaninstance
*whenaclientinvokesamatchingcreate<METHOD>(...)methodontheentitybean?s
*homeinterface.<br>
*
*Theentitybeanprovider?sresponsibilityistoinitializetheinstanceintheejbCreate<
*METHOD>(...)methodsfromtheinputarguments,usingthegetandsetaccessor
*methods,suchthatwhentheejbCreate<METHOD>(...)methodreturns,thepersistent
*representationoftheinstancecanbecreated.<br>
*
*Theentitybeanprovidermustnotattempttomodifythevaluesofcmr-fieldsinanejbCreate<
*METHOD(...)method;thisshouldbedoneintheejbPostCreate<METHOD(...)methodinstead.<br>
*
*TheentityobjectcreatedbytheejbCreate<METHOD>methodmusthaveauniqueprimary
*key.Thismeansthattheprimarykeymustbedifferentfromtheprimarykeysofalltheexisting
*entityobjectswithinthesamehome.However,itislegaltoreusetheprimarykeyofapreviously
*removedentityobject.Theimplementationofthebeanprovider?sejbCreate<
*METHOD>(...)methodsshouldbecodedtoreturnanull.<br>
*
*AnejbCreate<METHOD>(...)methodexecutesinthetransactioncontextdeterminedby
*thetransactionattributeofthematchingcreate<METHOD>(...)method.
*Thedatabaseinsertoperationsareperformedbythecontainerwithinthesame
*transactioncontextaftertheBeanProvider?sejbCreate<METHOD>(...)methodcompletes.
*
*@throwsCreateExceptionThrownifmethodfailsduetosystem-levelerror.
*
*@throwsCreateException
*
*@ejb.create-method
*/
publicLongejbCreate()throwsCreateException...{
returnnull;
}
/***//**
*ForeachejbCreate<METHOD>(...)method,thereisamatchingejbPostCreate<
*METHOD>(...)methodthathasthesameinputparametersbutwhosereturntypeis
*void.ThecontainerinvokesthematchingejbPostCreate<METHOD>(...)methodon
*aninstanceafteritinvokestheejbCreate<METHOD>(...)methodwiththesamearguments.
*TheinstancecandiscovertheprimarykeybycallinggetPrimaryKey()onits
*entitycontextobject.<br>
*
*TheentityobjectidentityisavailableduringtheejbPostCreate<METHOD>(...)
*method.Theinstancemay,forexample,obtainthecomponentinterfaceoftheassociatedentity
*objectandpassittoanotherenterprisebeanasamethodargument.<br>
*
*TheentityBeanProvidermayusetheejbPostCreate<METHOD>(...)tosetthevalues
*ofcmr-fieldstocompletetheinitializationoftheentitybeaninstance.
*AnejbPostCreate<METHOD>(...)methodexecutesinthesametransactioncontextas
*thepreviousejbCreate<METHOD>(...)method.
*
*@throwsCreateExceptionThrownifmethodfailsduetosystem-levelerror.
*/
publicvoidejbPostCreate()throwsCreateException...{
}
publicvoidejbActivate()throwsEJBException,RemoteException...{
//TODOAuto-generatedmethodstub
}
publicvoidejbLoad()throwsEJBException,RemoteException...{
//TODOAuto-generatedmethodstub
}
publicvoidejbPassivate()throwsEJBException,RemoteException...{
//TODOAuto-generatedmethodstub
}
publicvoidejbRemove()
throwsRemoveException,
EJBException,
RemoteException...{
//TODOAuto-generatedmethodstub
}
publicvoidejbStore()throwsEJBException,RemoteException...{
//TODOAuto-generatedmethodstub
}
/***//**
*Settheassociatedentitycontext.Thecontainercallsthismethod
*aftertheinstancecreation.Theentitybeanmustnotattemptto
*accessitspersistentstateandrelationshipsusingtheaccessor
*methodsduringthismethod.<br>
*
*Theenterprisebeaninstanceshouldstorethereferencetothecontext
*objectinaninstancevariable.<br>
*
*Thismethodiscalledwithnotransactioncontext.
*
*@throwsEJBExceptionThrownifmethodfailsduetosystem-levelerror.
*/
publicvoidsetEntityContext(EntityContextnewContext)throwsEJBException...{
context=newContext;
}
/***//**
*Unsettheassociatedentitycontext.Acontainerinvokesthismethod
*beforeterminatingthelifeoftheinstance.Theentitybeanmustnot
*attempttoaccessitspersistentstateandrelationshipsusingthe
*accessormethodsduringthismethod.<br>
*
*Thismethodiscalledwithnotransactioncontext.
*
*@throwsEJBExceptionThrownifmethodfailsduetosystem-levelerror.
*/
publicvoidunsetEntityContext()throwsEJBException...{
context=null;
}
/***//**
*@ejb.interface-methodview-type="both"
*@ejb.persistencecolumn-name="roleId" //表明该方法所对应的数据表名
*@ejb.pk-field //如果该字段是主键需要加上这么一个字段
*@return
*/
publicabstractLonggetRoleId();
/***//**
*@ejb.interface-methodview-type="both"
*@paramroleId
*/
publicabstractvoidsetRoleId(LongroleId);
/***//**
*@ejb.interface-methodview-type="both"
*@ejb.persistencecolumn-name="roleName"
*@return
*/
publicabstractStringgetRoleName();
/***//**
*@ejb.interface-methodview-type="both"
*@paramroleName
*/
publicabstractvoidsetRoleName(StringroleName);
}
注:在以上代码中类上面的javadoc红字表示解释和需要自己添加的代码。并且下面方法上面的Javadoc也是需要自己添加的同时这些方法,也得自己动手,丰衣足食(MyEclipse的Entity Bean做的非常不好,几乎什么都要自己添加,大概MyEclipse觉得Entity Bean马上就要被ORM的框架取代了)
以上我们Entity Bean的代码阶段就完成了,下面就是配置Xdoclet
五、配置Xdoclet
- 选择刚才所建立的工程,选择属性。选择工程右击--propertise
- 配置Xdoclet。刚才的对话框,Myeclipse--Xdoclet。在上面的框中右击选择Add Standard出现对话框,选择Standard EJB
- 选中刚刚添加的Standard EJB的节点,下面的框中会出现该选项所拥有的列表,选中其中的根节点:ejbdoclet右击Add,在出现的对话框中的选择weblogic
- 在同样的框中选中刚才添加的weblogic节点,在右边的属性列表中对以下节点进行修改
version----------8.1(因为我的Weblogic是8.1)
datasource----------刚才在配置weblogic的数据源名
destDir------src/META-INF(就是我们建立工程时src文件夹下面看到的META-INF文件夹)
六、执行Xdoclet
- 选中工程右击找到MyEclipse菜单项,选中该菜单项下的Run Xdoclet子菜单,这时候Eclipse会执行Xdoclet
- 等执行完毕后,刚才只有一个文件的包下面会出现一批文件
- 部署该EJB工程
七、测试
- 启动Weblogic,启动完成后如果控制后台没有出现EJB部署成功的信息,需要到Weblogic下面重新部署
- 打开http://127.0.0.1:7001/console,在右菜单mydomain--Deployments--EJB Modules,进行Deploy a new EJB Module...配置
- 配置成功后,weblogic会提示Deploy成功(可能需要等一会儿)
测试代码
publicstaticvoidmain(String[]args)...{
Propertiesproperties=newProperties();
//Weblogicconfigurationcode
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
properties.setProperty(Context.PROVIDER_URL,"t3://localhost:7001");
//t3://localhost:7001weblogicserveraddressandport
try...{
Contextcontext=newInitialContext(properties);
RoleHomeroleH=(RoleHome)context.lookup("ejb/Role");
Rolerole=roleH.findByPrimaryKey(newLong(100001));
System.out.println("theRoleNameis"+role.getRoleName());
}catch(NamingExceptione)...{
e.printStackTrace();
}catch(RemoteExceptione)...{
e.printStackTrace();
}catch(FinderExceptione)...{
e.printStackTrace();
}
}
分享到:
相关推荐
MyEclipse + WebLogic 9.2 配置详解,MyEclipse + WebLogic 9.2 配置详解
MyEclipse+WebLogic配置详解[参考].pdf
MyEclipse6.5 + Weblogic10的配置
Myeclipse+weblogic断点调试jsp.pdf
零基础学习MyEclipse+Weblogic9.x安装、配置、部署
安装 WebLogic 比较容易,在这里就不再累述了,大家可以参阅相关文档。现在着重讲一下 WebLogic 的配置,因为后面在配置 MyEclipse 时将用到这里的配置信息。
Weblogic 8.1的安装与配置.doc,我自己整理的,可用。
在myeclipse中配置weblogic8.1详细说明
搭建Eclipse3.2.2+MyEclipse5.5+Tomcat+Weblogic
*Project:weblogic_pool *类 名:UserDao.java */ public class UserDaoImpl implements UserDao { Connection conn=null; public List getUserList() throws Exception { conn = DataSourceUtil.get...
myeclipse+weblogic
Unable to start WebLogic Server! Error: license signature validation error. Please make sure you have a valid license.bea file in the BEA home directory associated with this installation. For more ...
MyEclipse默认的应用服务器为JBoss3,这里我们使用WebLogic8.1。启动Eclipse,选择“窗口\首选项”菜单,打开首选项对话框。展开MyEclipse下的Application Servers结点,点击JBoss 3,选中右面的Disable单选按钮,...
这是一个完整的文件批量上传项目,在weblogic myeclipse测试通过。
Myeclipse5.5 + Weblogic9.2 configure.doc
WebLogic 8.1 + MySQL + MyEclipse数据源的配置.doc,可行参考。
基于网站开发工具MyEclipse+ MySQL的新闻发布系统.pdf基于网站开发工具MyEclipse+ MySQL的新闻发布系统.pdf基于网站开发工具MyEclipse+ MySQL的新闻发布系统.pdf基于网站开发工具MyEclipse+ MySQL的新闻发布系统.pdf...
MyEclipse6.0下配置Weblogic8.1的详细说明
MyEclipse+Tomcat+MySQL的环境搭建.txt
MyEclipse 5.0 + WebLogic 9.2 配置解.doc