- 浏览: 3502615 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
wanglf1207:
EJB的确是个不错的产品,只是因为用起来有点门槛,招来太多人吐 ...
weblogic-ejb-jar.xml的元素解析 -
qwfys200:
总结的不错。
Spring Web Flow 2.0 入门 -
u011577913:
u011577913 写道也能给我发一份翻译文档? 邮件437 ...
Hazelcast 参考文档-4 -
u011577913:
也能给我发一份翻译文档?
Hazelcast 参考文档-4 -
songzj001:
DbUnit入门实战
https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html
Here are answers to some frequently asked questions about how to use Enterprise Java Beans within GlassFish. Additional resources can be found here . Please send any follow-up questions/comments to ejb@glassfish.dev.java.net or the GlassFish forum .
EJB Clients
-
How do I access a Remote EJB component from a stand-alone java client?
-
Is a stand-alone Java client portable? What's the difference between a stand-alone Java client and an Application Client component?
-
How do I access a Remote EJB (3.0 or 2.x) component from a non-Java EE web container like Tomcat or Resin?
-
What if I have multiple instances of the Appserver running and I want to access a Remote EJB component between them?
-
What is the relationship between @EJB and <ejb-ref> /<ejb-local-ref> ?
-
I have a Remote EJB dependency (@EJB or <ejb-ref> ) in my Java EE component. How do I control which actual target EJB component it refers to?
Local EJB Access
-
How do I access a Local EJB component from a POJO or utility class?
-
I have an EJB component with a Local interface. Can I access it from an Application Client or a stand-alone java client ?
JNDI names
Testing / Embeddable API
How do I access a Remote EJB component from a stand-alone java client?
Step 1. Use the no-arg InitialContext() constructor in your code.
The most common problem developers run into is passing specific
JNDI
bootstrapping properties to InitialContext(args)
.
Some other
vendors require this step but GlassFish does not
. Instead, use the
no-arg InitialContext()
constructor.
Step 2. Pass the global JNDI name of the Remote EJB to InitialContext.lookup()
Stand-alone java clients do not have access to a component naming
environment (java:comp/env
)
or to the @EJB
annotation, so they must
explicitly use the global JNDI
name
to lookup the Remote EJB.
(See here
for
more information on how global JNDI
names
are assigned to EJB components)
Assuming the global JNDI
name
of the Remote EJB is "FooEJB"
:
For Beans with a 3.x Remote Business interface : Foo foo =
(Foo) new InitialContext().lookup("FooEJB");
Note that in the EJB 3.x case the result of the
lookup can be directly
cast to the remote business interface type without using
PortableRemoteObject.narrow()
.
For EJB 2.1 and earlier session/entity beans :
Object homeObj = new
InitialContext().lookup("FooEJB");
FooHome fooHome = (FooHome)
PortableRemoteObject.narrow(homeObj,FooHome.class);
Foo foo = fooHome.create(...)
Step
3.
Include the appropriate GlassFish .jars in the java client's
classpath.
For GlassFish v3
Include $GLASSFISH_HOME/modules/gf-client.jar
in the client's
classpath.
E.g., assuming the application classes are in /home/user1/myclasses and
the main client class is acme.MyClient
:
java
-classpath
$GLASSFISH_HOME/modules/gf-client.jar:/home/user1/myclasses
acme.MyClient
Note that the Java EE 6 API classes are automatically included by
gf-client.jar
so there is no need to explicitly add javaee.jar to the
classpath. gf-client.jar
refers to many other .jars from the
GlassFish installation directory so it is best to refer to it from
within the installation directory itself rather than copying it(and all
the other .jars) to another location.
For GlassFish v2 and earlier
Include both $GLASSFISH_HOME/lib/appserv-rt.jar
and
$APS_HOME/lib/javaee.jar
in the client's classpath.
E.g., assuming the application classes are in /home/user1/myclasses and
the main client class is acme.MyClient
:
java
-classpath
$GLASSFISH_HOME/lib/appserv-rt.jar:$GLASSFISH_HOME/lib/javaee.jar:/home/user1/myclasses
acme.MyClient
Note : appserv-rt.jar
uses the JAR MANIFEST-CLASSPATH attribute to
include other dependent .jars within the lib directory. When
setting your
client classpath, it is best to directly refer to the appserv-rt.jar
within
the app server lib directory rather than copying it to another
location.
If you do copy appserv-rt.jar
,
you'll need to copy additional
.jars
such as appserv-deployment-client.jar
and appserv-ext.jar
.
The
full set of .jars that might be needed by appserv-rt.jar is located in
its
META-INF/MANIFEST.MF file.
If your stand-alone client makes use of JMS, you'll also need to add
$GLASSFISH_HOME/lib/install/applications/jmsra/imqjmsra.jar
,
$GLASSFISH_HOME/lib/appserv-admin.jar
and $GLASSFISH_HOME/lib/appserv-ws.jar.
If your stand-alone client makes use of the Java Persistence API (e.g.
it calls a Remote EJB component that returns a Java Persistence API
entity
), you'll also need to add $APS_HOME/lib/toplink-essentials.jar.
Step 4. Set the server host property, if necessary.
If the stand-alone java client is running on a different host than the
server, set the -Dorg.omg.CORBA.ORBInitialHost
property when starting
the client JVM. E.g.
java
-Dorg.omg.CORBA.ORBInitialHost=com.acme.Host1
. This
property
defaults to localhost
,
so it is not necessary to set it if the java
client is running on the same machine as the server.
Step 5. Set the naming service port property, if necessary.
The default naming service port in the app server is 3700
.
If
the naming service is running on a different port, you'll need to
set it via the -Dorg.omg.CORBA.ORBInitialPort
property when starting
the
client JVM. You can double-check the actual naming service port
for a given server instance by looking in the server instace's
domain.xml
for "orb-listener-1"
.
Alternatively, check the
Applications..Configuration..ORB..IIOP Listeners section of the admin
GUI for orb-listener-1
.
Is a stand-alone Java client portable? What's the difference between a stand-alone Java client and an Application Client component?
The Java EE platform defines a component that is specially designed to
portably access Java EE services from a JVM running outside of the
Application Server. It is called a Java EE Application Client
and has been
part of the platform since the first release (J2EE 1.2). Like
all
Java EE components it runs within a container provided by the vendor's
implementation. The main advantages of the Application Client are
that it's portable and that it allows the developer to use the same
programming
model for defining and accessing resources as is used within web
components
and EJB components. It follows the overall philosophy of the Java
EE
platform
that as much of the "plumbing" or system-level work as possible should
be performed by a container instead of being part of the Application
code.
That means a guarantee that the no-arg InitialContext
constructor
will work, that a private component naming context (java:comp/env
)
is
available,
and in Java EE 5 that platform annotations and injection are available.
One of the most common issues faced by developers is how to initialize
the naming context within a client that accesses EJB components.
When such
a client is *not* written as an Application Client it is referred to as
a "stand-alone" java client. By definition, such stand-alone java
clients are not portable, so each vendor defines its own way to
bootstrap
the naming service. This not only makes it more difficult to code the
client
but causes problems when moving between Java EE implementations.
Like all Java EE components, there are some additional steps required
to achieve the portability offerered by the Application Client.
E.g., definining a deployment descriptor, packaging the
application client .jar and learning how to run the Application Client
container.
See the following for more details on using Application Clients :
Chapter 22
(Getting Started with EJBs) of the Java EE 5 tutorial
Simple
EJB 3.0 session / message-driven bean code examples
Client
chapter of our Developer's Guide
How do I access a Remote EJB (3.0 or 2.x) component from a non-Java EE web container like Tomcat or Resin?
Accessing a Remote EJB component from a non-Java EE web container is similar to the stand-alone java client case. However, the complication is that most Java web servers set the default JNDI name provider for the JVM, which prevents our appserver naming provider from being instantiated when the application uses the no-arg InitialContext() constructor. The solution is to explicitly instantiate an InitialContext(Hashtable) with the properties for our naming provider, as contained in GlassFish's jndi.properties file.
Step 1. Instantiate the InitialContext
Properties props = new
Properties();
props.setProperty("java.naming.factory.initial",
"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
"com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state",
"com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
// optional. Defaults to localhost. Only
needed if web server is running
// on a different host than the appserver
props.setProperty("
org.omg.CORBA.ORBInitialHost
",
"localhost
");
// optional. Defaults to 3700. Only needed if
target orb port is not 3700.
props.setProperty("
org.omg.CORBA.ORBInitialPort
",
"3700");
InitialContext ic = new InitialContext(props);
Step 2. Use the global JNDI name of the target Remote EJB in the lookup.
EJB 3.x, assuming a global JNDI name
of "com.acme.FooRemoteBusiness"
:
FooRemoteBusiness foo =
(FooRemoteBusiness)
ic.lookup("com.acme.FooRemoteBusiness");
EJB 2.x, assuming a global JNDI name
of "com.acme.FooHome"
:
Object obj = ic.lookup("com.acme.FooHome");
FooHome fooHome = (FooHome)
PortableRemoteObject.narrow(obj, FooHome.class);
Step 3. Add the necessary appserver code to the web server's classpath.
See step 3 of
stand-alone client access
for the list of required .jars.
Step 4. For EJB 3.0 Remote access, use at least Glassfish V2 or Java EE 5 SDK(SJS AS 9) Update 1.
Builds from this point on will contain a required bug fix.
See
https://glassfish.dev.java.net/issues/show_bug.cgi?id=920
for
more details.
What if I have multiple instances of the Appserver running and I want to access a Remote EJB component between them?
If the two server instances are part of the same cluster, there is no
special mapping needed. By definition, a cluster is homogeneous,
meaning
the exact same set of applications is deployed to all instances.
Each server instance has the same entries in its global JNDI
namespace,
so
the target Remote EJB component can always be resolved intra-server.
Therefore,
it would never be a good idea to explicitly refer to a Remote EJB
component in
one
server instance in the cluster from a different server instance in the
same
cluster.
However, if the server instances are either both stand-alone instances
or this a cross-cluster access, the only difference is the syntax of
the
global JNDI
name used to resolve the ejb-ref
or @EJB
.
Since the
calling
code is running within a Java EE component (web or ejb), it should use
the
standard Java EE programming model for accessing remote EJB components
-- @EJB
or
ejb-ref +
java:comp/env
lookup. The application code and any
ejb-ref
.xml should remain location transparent so that the mapping to physical
EJB component can be changed without affecting any portable code or
descriptors.
Follow the steps outlined here
, but instead of using an unqualified global JNDI
name,
use the CORBA
interoperable naming syntax :
corbaname:iiop:<host>:<port>#<global_jndi_name>
E.g., assume we have a web application running in a non-clustered app
server instance on host1
that
wants to access a Remote Stateless
Session bean in an app server instance on host2
.
The target
Remote EJB component has a global JNDI
name
of "Foo"
.
Within the servlet : @EJB(name="fooejbref")
private FooRemote fooRemote;
Within sun-web.xml
:
<ejb-ref>
<ejb-ref-name>fooejbref</ejb-ref-name>
<jndi-name>corbaname:iiop:host2:3700#Foo</jndi-name>
</ejb-ref>
Do I need RMI stubs to access EJBs from my java client?
No. Our implementation
uses a feature called "Dynamic RMI-IIOP" that creates any necessary
RMI-IIOP
stubs at runtime in a way that is completely hidden from the
application. This makes deployment much faster and avoids
many of the configuration problems that result from having to add
static stubs to your client. However, Dynamic RMI-IIOP is only
enabled when the client is using the naming provider
from our server implementation. If the
client is a stand-alone java client, that means following the
instructions
here
or here
, or using an
Application Client component. Any explicit use of the CosNaming
provider in the
client will not be able to use the dynamic RMI-IIOP feature,
which is
why
we don't recommend that approach. If you must use CosNaming
,
see here
.
What if I have an existing stand-alone java client that accesses EJB components through the CosNaming JNDI provider ? How do I get static RMI-IIOP stubs for it?
First, read about Portable Java EE clients
and "How To Write a Stand-alone Client"
.
The best option would be to change the client to an Application
Client or to follow our stand-alone java client recommendations.
If
that's not possible, you can request that static RMI-IIOP
stubs be
generated
during deployment by using the --generatermistubs
option on the
asadmin
deploy
command. In this case, the static RMI-IIOP
stubs
will
be placed within the client.jar file. E.g.
asadmin deploy --generatermistubs --retrieve
/home/user1/clientstubdir fooapp.ear
After the command executes, the client.jar containing the static
RMI-IIOP
stubs will be in /home/user1/clientstubdir/fooappClient.jar
.
The reason static RMI-IIOP
stubs are still needed in this case is that
if the CosNaming
provider is instantiated, it is not using the client
naming provider from our appserver implementation. It instead
uses an ORB from Java SE which does not support dynamic RMI-IIOP.
What is the relationship between @EJB and ejb-ref /ejb-local-ref ?
The @EJB
annotation and the ejb-ref
/ejb-local-ref
.xml elements are
used to specify the same semantic information. Specifically, that
a Java EE component has a dependency on a local or remote EJB
component.
Every @EJB
can be translated into an equivalent
ejb-ref
/ejb-local-ref
.
@EJB
is easier to use but it serves the
same purpose as ejb-ref
/ejb-local-ref
.
Here's a table with more
details :
@EJB
attribute
|
Description
|
Default value
|
ejb-ref
equivalent |
ejb-local-ref
equivalent |
name
|
Unique location within the private component
namespace(java:comp/env
).
|
field-level : <fully-qualified
name of
declaring class>/<field-name>
method-level : <fully-qualified name of declaring class>/<property name> class level : name is required. |
ejb-ref-name
|
ejb-ref-name
|
beanInterface
|
For EJB 3.x business interfaces, the Local or
Remote business interface of the session bean. For EJB 2.x, the Home/LocalHome interface of the session/entity bean. |
field-level : the type of the declared field. method-level : the type of the single setter parameter class level : beanInterface is required. |
For EJB 3.x : <remote>
For EJB 2.x : <home> |
For EJB 3.x : <local> For EJB 2.x : <local-home> |
beanName
|
ejb-name
(not
global JNDI
name)
of the target
ejb component within the application. This can be used whenever
the target
ejb
component is defined within the same application as the referencing
component,
regardless of local vs. remote. The only time it can't be used
is if the @EJB
refers to a Remote interface (3.x or 2.x) that is
defined outside the application. |
Automatically resolved if there is only one EJB
component within the application that exposes the value of beanInterface
|
ejb-link
|
ejb-link
|
lookup *(Added in EJB 3.1) |
Specifies the portable JNDI
name
of the target EJB component to which this @EJB
dependency refers. This should be used instead of mappedName
in cases where an @EJB
dependency needs to be resolved to a Remote EJB component defined in a
different application. It can also be used to chain one @EJB
dependency to another @EJB
dependency. |
n/a |
lookup-name
|
lookup-name |
mappedName
|
Specifies the product-specific name of the
target Remote EJB component. For GlassFish, this refers to the
global JNDI
name of the target Remote EJB component. Not applicable for local interfaces because beanName can always be used instead. *(Should not be used in EJB 3.1. See lookup instead) |
If the target EJB component is defined within
the same
application and the beanName
default applies, no additional mapping
is required. Otherwise, the target global JNDI name will be set to the value of beanInterface |
mapped-name
|
n/a |
I have a Remote EJB
dependency (@EJB or <ejb-ref>) in my Java EE component. How
do I
control which
actual target EJB component it refers to?
If the target EJB component is defined within the same application as
your
referencing component and
there is only one target EJB component within the
application that exposes the remote interface associated with your EJB
dependency, then the mapping will happen automatically. In this
case, there is no need to specify any additional mapping information.
Otherwise, there are 3 ways to map the remote EJB dependency to the
target Remote EJB component. From highest to lowest precedence,
they are :
1. Use the sun-specific deployment descriptor
Map the remote EJB dependency to the global JNDI
name
of the target EJB component
within the sun-*.xml
{sun-web.xml
,
sun-application-client.xml
,
sun-ejb-jar.xml
}
file corresponding to the module in which the EJB
dependency is defined.
E.g. given a remote EJB dependency defined within a servlet
(com.acme.MyServlet
)
:
@EJB(name="fooejbref")
private FooRemote fooRemote;
To map this remote EJB dependency to an EJB comopnent with global JNDI
name "Foo"
:
Within sun-web.xml
: <ejb-ref>
<ejb-ref-name>fooejbref</ejb-ref-name>
<jndi-name>Foo</jndi-name>
</ejb-ref>
If the @EJB
did not use the name
attribute, you would need to refer
to the default name of the EJB dependency when specifying the
sun-*.xml
mapping. E.g. :
@EJB
private FooRemote fooRemote;
To map this remote EJB dependency to an EJB component with global JNDI
name "Foo"
:
Within sun-web.xml
:
<ejb-ref>
<ejb-ref-name>com.acme.MyServlet/fooRemote</ejb-ref-name>
<jndi-name>Foo</jndi-name>
</ejb-ref>
2. Use @EJB mappedName or the <ejb-ref>.. <mapped-name> element.
For @EJB
,
specify the global JNDI
name
of the target EJB component using the
mappedName
attribute. E.g.
@EJB(name="fooejbref", mappedName="Foo")
private FooRemote fooRemote;
Note that mappedName
is completely different
than name
.
name
refers to a location within the private component
environment namespace (java:comp/env
)
that represents this EJB
dependency. mappedName
refers to
a location within a product-specific global
namespace that holds the EJB reference object.
For <ejb-ref
>,
specify the global JNDI
name
of the target EJB component using the
<mapped-name
>
element. E.g.
<ejb-ref>
<ejb-ref-name>fooejbref</ejb-ref-name>
<remote>com.acme.FooRemote</remote>
<mapped-name>Foo</mapped-name>
</ejb-ref>
If an @EJB
and
an <ejb-ref>
are
defined for the same EJB
dependency(meaning @EJB.name
equals <ejb-ref>..<ejb-ref-name>
)
in the same component
environment, the values in <ejb-ref>
take precedence.
3. Use @EJB beanName or <ejb-ref>..<ejb-link> element.
beanName
and <ejb-link>
only apply if the target remote EJB component is defined
within the same application as the referencing component.
In this case, the value is the ejb-name
of the target
bean, not
the global JNDI
name.
If the target EJB component is defined
using ejb-jar.xml
,
the ejb-name
is the value of the <session>
or <entity>
ejb-name
element. If the target EJB component is defined using
annotations, the
ejb-name
is either the value the @Stateless
/@Stateful/@Singleton
name
attribute or if
name
was not specified, the unqualified
bean class name.
E.g. , assuming our target EJB component com.acme.FooBean
is defined as follows
:
@Stateless
public class FooBean implements FooRemote { ... }
To map the servlet's EJB dependency using beanName
:
@EJB(name="fooejbref", beanName="FooBean")
private FooRemote fooRemote;
To map the servlet's EJB dependency using ejb-link
:
<ejb-ref>
<ejb-ref-name>fooejbref</ejb-ref-name>
<remote>com.acme.FooRemote</remote>
<ejb-link>FooBean</ejb-link>
</ejb-ref>
Note that ejb-name
is only guaranteed to be unique within an ejb-jar
or .war
module. If there are multiple modules within the .ear
that
define
an EJB component with the same ejb-name
,
the following beanName
/<ejb-link>
syntax
can
be used to explicitly refer to the target EJB component :
<relative
ejb-jar
module uri>#<ejb-name>
E.g., given an application containing ejb1.jar
, ejb2.jar
,
and web1.war
,
where ejb1.jar
and ejb2.jar
both define an EJB component with ejb-name FooBean
:
To map the servlet's EJB dependency to the EJB component in ejb1.jar
using
beanName
:
@EJB(name="fooejbref", beanName="ejb1.jar#FooBean")
private FooRemote fooRemote;
To map the servlet's EJB dependency to the EJB component in ejb1.jar
using ejb-link
: <ejb-ref>
<ejb-ref-name>fooejbref</ejb-ref-name>
<remote>com.acme.FooRemote</remote>
<ejb-link>ejb1.jar#FooBean</ejb-link>
</ejb-ref>
If an @EJB
and
an <ejb-ref>
are
defined for the same EJB
dependency(meaning @EJB.name
equals <ejb-ref>..<ejb-ref-name>
)
in the same component
environment, the values in <ejb-ref>
take precedence.
I have an EJB component with a Local interface. Can I access it from an Application Client or a stand-alone java client ?
If the EJB component is running within the server, no. The EJB
Local view is an optimized invocation path that uses
call-by-reference semantics. It is only available to web
components and EJB components that are part of the same application
as the target EJB component. To access EJB components that
are running in the server from an Application Client or
stand-alone java client, you'll need to use either a Remote 3.x
Business interface, a 2.x Home interface, or web services.
One alternative, if using GlassFish v3, is to use the EJB 3.1 Embeddable API
.
This allows a Java SE program to directly execute EJB components within
the same JVM, without using a server process.
I have an EJB component with a Local interface. Can I access it from a web component in a different application?
No. The EJB specification only requires access to an EJB
component's local EJB interface from
within the same application in the same JVM. One option is
to package the ejb-jar
in
the same .ear
as the .war
.
A
second option, if using GlassFish v3, is to package the EJB component
directly within the .war
.
How do I access a Local EJB component from a POJO?
Local EJB component access is only portable from within the same
application, so
the
POJO class must be called from a component running within the same
application
as the target Local EJB component. Injection is not supported for
POJO classes,
so the POJO needs to look up the local reference.
If the application is running within GlassFish v3, it can use the portable global JNDI
names defined by the EJB 3.1 specification
. In addition to
portable java:global
names, there are default portable JNDI
names
for
two other scopes : java:module
,
and java:app
.
An EJB component's java:module
JNDI
name is visible to any code running within the
same module. An EJB component's java:app
JNDI
name
is
visible to any code running within the same application.
The syntax for each is :
java:module/<bean-name>
java:app/<module-name>/<bean-name>
<module-name>
defaults to the unqualified name of the ejb-jar
file or .war
file in which the EJB component is defined, minus the file
extension. The <module-name>
can be explicitly
specified using
the <module-name>
element of the ejb-jar.xml
(for ejb-jars) or
web.xml
(for
EJB components defined in .wars).
<bean-name>
corresponds to the session bean's ejb-name
.
It
defaults to the unqualified
name of the session bean class. It
can be
explicitly specified using the name
attribute of the
@Stateless
/@Stateful
/@Singleton
annotation. Alternatively, if the
ejb-jar.xml
is being used to define the component, <bean-name>
corresponds to the <ejb-name>
element of ejb-jar.xml
.
So, given : @Stateless
public class FooBean { ... }
A POJO running within the same module as FooBean
can
lookup an EJB
reference to FooBean
using :
FooBean foo = (FooBean) new
InitialContext().lookup("java:module/FooBean");
An advantage of the java:module
syntax
vs. java:global
is that the code
doing the lookup does not have to know the <app-name>
or
<module-name>
in which it is executing.
If the application is running in GlassFish v2 or earlier, there are no
portable JNDI
names for the local EJB view. In that case the only
way for the POJO to acquire an EJB reference is to define a local EJB
dependency using @EJB
or ejb-local-ref
,
and then look up that
dependency within the private namespace
(java:comp/env
)
of the component within whose scope it is executing.
That can be done using the following steps :
Step 1. Define the local EJB dependency for the component within whose scope the POJO will execute.
Assume the POJO wants to access a local EJB 3.0 business interface
FooLocal
from the following EJB component defined within the same application :
@Stateless
public class FooBean implements FooLocal { ... }
If the POJO is called from a web application, the java:comp/env
namespace
is shared by the entire .war
.
So, the local EJB dependency can be
defined
by using an @EJB
annotation on any managed class within the .war
:
@EJB(name="fooejbref", beanInterface=FooLocal.class)
public class MyServlet extends HttpServlet { ... }
Likewise, if the POJO is itself called from an EJB component, the local
EJB
dependency
must be defined within that EJB component. Unlike the .war
case,
the
component environment (java:comp/env
)
is private for each EJB component.
@EJB(name="fooejbref", beanInterface=FooLocal.class)
@Stateless
public class BarBean implements BarLocal { ... }
Alternatively, the local EJB dependency can be declared within the
standard
deployment descriptor corresponding to the component within whose scope
the
POJO is executing (web.xml
/ ejb-jar.xml
)
<ejb>
<ejb-name>BarBean</ejb-name>
<ejb-class>com.acme.BarBean</ejb-class>
...
<ejb-local-ref>
<ejb-ref-name>fooejbref</ejb-ref-name>
<local>com.acme.FooLocal</local>
<ejb-link>FooBean</ejb-link>
</ejb-local-ref>
</ejb>
Step 2. In the POJO code, lookup the local EJB dependency within java:comp/env
InitialContext ic = new InitialContext();
FooLocal foo = (FooLocal)
ic.lookup("java:comp/env/fooejbref");
Note that if the POJO is called from multiple components, e.g. from
both
the web application and BarBean
,
you'll need to define the same local
EJB
dependency for both calling components so that it is always defined in
the
currently active component environment when the POJO does its lookup.
Are Global JNDI
names portable? How do I know if my EJB component has a portable
JNDI
name?
If the EJB component is a kind of session bean and it is deployed to
any implementation supporting EJB 3.1(E.g. GlassFish v3), it will
automatically have one or more portable JNDI
names
defined based on the
syntax in the EJB 3.1 specification. Note that this is true of
existing EJB 3.0 and 2.x applications that are deployed to an
implementation supporting EJB 3.1. No
code changes are required on the
bean class itself in order to have the portable global JNDI
name
automatically assigned when deployed to an EJB 3.1 container. See
here for EJB 3.1
portable
global JNDI
name syntax
.
Prior to EJB 3.1 (GlassFish v2 and earlier), there were no portable
global JNDI
names defined by the specification.
See GlassFish-specific
global JNDI
name syntax
.
What is the
syntax for portable global JNDI
names
in EJB 3.1?
Per the EJB 3.1 Specification, each session bean is assigned a unique
JNDI
name within the java:global
namespace. Note that prior to
EJB 3.1 / GlassFish v3, there were no portable JNDI
names defined for session beans, so each vendor defined its own
syntax. See
here for GlassFish vendor-specific global JNDI
name
syntax .
The syntax for portable global session bean JNDI
names
in EJB 3.1 is :
java:global[/<app-name>]/<module-name>/<bean-name>
The <app-name>
portion is only
present if
the application is
deployed as an .ear
file. In that case, <app-name>
defaults to the unqualified
name of the .ear
file, minus the file
extension. The <app-name>
can be explicitly specified
using the <app-name>
element in application.xml
.
<module-name>
defaults to the unqualified
name of the ejb-jar
file or .war
file in which the EJB component is defined, minus the file
extension. The <module-name>
can be explicitly
specified using the <module-name>
element of the ejb-jar.xml
(for
ejb-jars) or web.xml
(for
EJB components defined in .wars).
<bean-name>
corresponds to the session bean's EJB name. It
defaults to the unqualified
name of the session bean class. It
can be explicitly specified using the name
attribute of the
@Stateless
/@Stateful
/@Singleton
annotation. Alternatively, if the
ejb-jar.xml
is being used to define the component, <bean-name>
corresponds to the <ejb-name>
element of ejb-jar.xml
.
Given the session bean :
@Stateless
public class FooBean implements Foo { ... }
If FooBean
is packaged in fooejb.jar
and deployed as a stand-alone
module, its resulting JNDI
name
entry is :
java:global/fooejb/FooBean
If FooBean
is packaged in fooejb.jar
within fooapp.ear
,
its resulting
global JNDI
name entry is :
java:global/fooapp/fooejb/FooBean
If FooBean
is packaged in a stand-alone web module fooweb.war
,
its resulting
global JNDI
name is :
java:global/fooweb/FooBean
If FooBean</
发表评论
-
字符串分割--java中String.split()用法
2013-03-06 14:25 74151在java.lang包中有String.sp ... -
用 HttpServletResponseWrapper 实现 Etag 过滤器
2012-07-09 16:58 3758原文出处:http://blog.chenlb.com/200 ... -
Fitnesse使用
2012-05-05 13:27 23494Fitnesse 的使用 一,介绍 Fitnesse是一种 ... -
Customizing the new FitNesse parser
2012-05-05 13:13 2134FitNesse began its life using ... -
java application中内嵌ActiveX控件
2011-11-14 15:57 5524我这里用的是SWT/JFace开发application,SW ... -
Google Java Developer Tools Downloads
2011-08-09 00:04 2346WindowBuilder Pro原来叫WindowB ... -
Jalita
2011-08-06 00:49 1565Jalita (Java light terminal ada ... -
【转】用Java写字符终端界面
2011-07-29 13:13 2121终端界面GUI开源项目charva。 这个框架让你可以用开发 ... -
[转]mybatis下的分页,支持所有的数据库
2011-07-21 13:21 14841大 家都知道,mybatis的自带分页方法只是逻 ... -
Java framework for text- & console-based forms?
2011-07-21 01:06 1711charva jcurses JNA , ... -
JNA(Java Native Access)学习入门
2011-07-21 01:04 22621Java Native Access 项目 在 ... -
JAVA上加密算法的实现用例
2011-06-25 12:38 4883来源:www.ibm.com ... -
如何将GlassFish作为Windows服务运行
2011-05-18 23:21 2374本文档来自GlassFish官方网站,详细介绍了将 G ... -
JAVA UDP打洞必备知识点---NAT
2011-05-05 12:56 8699一、引言 RFCl631 ... -
Keystore概念,Keytool工具使用
2011-04-28 16:20 2906近来由于项目需要做Single Sign On, 研究了一 ... -
利用Eclipse Profile Plugin监控分析Tomcat性能
2011-04-18 16:14 3702目前新版本的Eclipse在启动应用服务器的时候有一个新的选 ... -
m2eclipse: Eclipse is running in a JRE, but a JDK is required
2011-02-04 23:43 2541Eclipse 安装了Maven插件,启动Eclipse ... -
利用JNative实现Java调用动态库
2010-10-18 00:43 2100由于项目要求,需要用J ... -
RHEL5支持大内存
2010-10-08 16:19 3005安装 RHEL 5 ,硬件为 4G 内存,安装完成 ... -
Windows Server 2003 和 Windows 2000 提供大内存支持
2010-10-08 16:19 1854本文介绍物理地址扩展 ...
相关推荐
10. **Java EE**:对于服务器端开发,可能会涉及Servlet、JSP、EJB、Spring、Hibernate等企业级应用框架。 11. **JVM原理**:了解Java虚拟机的工作原理,如类加载机制、内存模型和字节码执行,有助于优化程序性能。...
J2EE_FAQ.txt可能包含关于Java企业版(Java Enterprise Edition,现在称为Jakarta EE)的问题和解答,涵盖Web服务、EJB(Enterprise JavaBeans)、Servlets、JSP(JavaServer Pages)、JMS(Java Message Service)...
#### 7.2 常见问题说明FAQ - **内容**:列出管理员在使用过程中可能遇到的问题及解决方案。 - **价值**:为用户提供快速解决问题的方法,提高工作效率。 以上内容是对JTangEJB管理员手册中的核心知识点的总结,这些...
- **J2EE**:即Java 2 Platform Enterprise Edition(Java 2平台企业版),主要用于构建大型的企业级应用程序和服务,提供了对Web服务、EJB等的支持。 - **J2ME**:即Java 2 Platform Micro Edition(Java 2平台微型...
4. **Workshop**:WebLogic Workshop是BEA Systems(后被Oracle收购)为WebLogic Server配套的开发工具,专为开发J2EE应用设计,支持PageFlow架构,便于创建Web应用、EJB和Web服务。随着Oracle JDeveloper的推广,...
- 常见问题解答(FAQ):解答了用户在使用过程中可能遇到的问题和疑惑。 5. **主要应用场景** - **EJB开发**: XDoclet可以自动创建EJB组件的相关部署描述符,如ejb-jar.xml、ejb-client.jar等。 - **JDBC和...
- **第七章**:提供了常见问题的解答,即FAQ。 - **文档受众**:主要面向已经熟悉J2EE架构和EJB规范的开发者。这些开发者通常需要进行系统设计、开发或维护工作,尤其是在JTang应用服务器EJB模块方面。 - **假设...
同时,了解和熟悉这些文档(FAQ(JAVA基础一)-整理.doc、FAQ(JAVA基础二)整理.doc、FAQ(数据结构).docx、FAQ(面向对象).docx、FAQ(J2EE).docx、FAQ(数据库).docx)中的内容,可以帮助你更好地准备面试。
5. 服务咨询:提供在线客服或FAQ,解答用户疑问,提供帮助。 三、J2EE技术在银行系统中的应用 1. Servlet:作为HTTP请求的处理者,Servlet接收用户的请求,调用业务逻辑处理后返回响应。 2. JSP:用于创建动态网页...
本书的编写是基于JSP FAQ的发展,该FAQ目前位于http://www.esperanto.org.nz/jsp/jspfaq.html。在介绍JSP语法时,我们将采用灰色背景框来呈现,以避免重复规范中的内容。书中有几种特殊符号表示特定含义:一个指示...
- **基本类型配置**:说明了进行Hibernate注解配置时需要引入的相关JAR包,包括`hibernate-annotation.jar`、`ejb3persistence.jar`和`hibernate-common-annotations.jar`。 - **注解使用**:具体到注解的使用方法,...
这部分讲解了Java程序与数据库交互的技术,包括JDBC、EJB等,以及如何使用Java Bean来简化开发流程。 #### 6. Distributed Systems 介绍了分布式系统的概念和实现方法,帮助开发者理解如何构建可扩展和高性能的Java...
在深入探讨其配置与管理之前,我们首先需要了解Java EE的概念,它是企业级软件开发的标准,包括了诸如Servlet、JSP、EJB等组件,用于构建可伸缩、高可用性的分布式系统。 Websphere Application Server 6.0版本在...
Jetty 欢迎访问Jetty文档 Wiki.... 这个wiki提供jetty的入门教程、基础配置、功能特性、优化、安全、JavaEE、监控、常见问题、故障排除帮助等等。它包含教程、使用手册、视频、...FAQ Contributing Contributing to Jetty
- **关键技术**:如RMI(远程方法调用)、EJB(企业JavaBeans)等。 #### 2.5 File Systems - **文件操作**:包括文件的读写、目录的创建与删除等基本操作。 - **文件流**:如使用InputStream和OutputStream进行...
这本PDF文档,名为“1000_Java_Tips_low.pdf”,是由javafaq网站精心编撰的,旨在为Java开发者提供1000个实用的编程技巧和最佳实践。这份资料无疑是Java开发者提升技能、优化代码、解决问题的重要参考资料。 首先,...
Java Web开发是软件行业中一个广泛讨论的话题,涵盖了从服务器端编程到前端交互的诸多技术。这份文档显然旨在帮助Java开发者,...这份文档的FAQ部分可能包含了对这些知识点的解答,是准备面试和提升技能的宝贵资源。
附录部分包括了FAQ(常见问题解答),这里收集了用户在使用JTang应用服务器及其插件时遇到的常见问题及其解决方案,为用户提供了解决问题的快捷途径。 总之,JTang应用服务器用户使用手册为用户提供了详尽的JTang...
<br>Hibernate网站的“社区(Community Area)”是讨论关于设计模式以及很多整合方案(Tomcat, JBoss AS, Struts, EJB,等等)的好地方。 <br>如果你有问题,请使用Hibernate网站上链接的用户论坛。我们也提供一...
<br>Hibernate网站的“社区(Community Area)”是讨论关于设计模式以及很多整合方案(Tomcat, JBoss AS, Struts, EJB,等等)的好地方。 <br>如果你有问题,请使用Hibernate网站上链接的用户论坛。我们也提供一...