Dependency Injection of EJB in application client
Hello,
I did a quick search and did not find a similar posting on this. I apologize if I missed one.
I wrote a simple stateless session bean based on EJB 3.0 specification. I wrote a simple client called TestCVTApplication. I am hoping to inject this EJB. Here is how I defined my application-client.xml
<?xml version="1.0" encoding="UTF-8"?>
<application-client xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/application-client_1_4.xsd"
version="1.4">
<ejb-ref>
<ejb-ref-name>cvt.server.HelloBean</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<remote>cvt.server.Hello</remote>
<injection-target>
<injection-target-class>cvt.client.TestCVTApplication</injection-target-class>
<injection-target-name>helloEJB</injection-target-name>
</injection-target>
</ejb-ref>
<callback-handler>
cvt.client.MyCallbackHandler
</callback-handler>
</application-client>When I run my client, I am getting the below exception
Exception in thread "main" java.lang.InstantiationException: Injection of multiple references to the same target[class = cvt.client.TestCVTApplication, field/property = helloEJB]
Thanks for your help.
Mustafa
Injection is required to be supported in Application Client main classes. This error probably means you have defined two different dependencies that have the same target field name in the main class. Did you put an @EJB annotation in the main class in addition to adding the ejb-ref in the application-client.xml? You should just use either one or the other. Also make sure that the field in the main class has a "static" modifier.
--ken
Similar Messages
-
I unable to run ejb with application client using oc4j j2ee container
Hi,
I have installe oracle9i (1.0.2.2) oc4j j2ee container.
I unable to run the ejbs . please help me how to run ejbs with application client and which files are shall configure.
See the client application is :
public static void main (String []args)
try {
//Hashtable env = new Hashtable();
//env.put("java.naming.provider.url", "ormi://localhost/Demo");
//env.put("java.naming.factory.initial", "com.evermind.server.ApplicationClientInitialContextFactory");
//env.put(Context.SECURITY_PRINCIPAL, "guest");
//env.put(Context.SECURITY_CREDENTIALS, "welcome");
//Context ic = new InitialContext (env);
System.out.println("\nBegin statelesssession DemoClient.\n");
Context context = new InitialContext();
Object homeObject = context.lookup("java:comp/env/DemoApplication");
DemoHome home= (DemoHome)PortableRemoteObject.narrow(homeObject, DemoHome.class);
System.out.println("Creating Demo\n");
Demo demo = home.create();
System.out.println("The result of demoSelect() is.. " +demo.sayHello());
}catch ( Exception e )
System.out.println("::::::Error:::::: ");
e.printStackTrace();
System.out.println("End DemoClient....\n");
When I am running client application I got this type of Exception
java.lang.SecurityException : No such domain/application: sampledemo
at com.evermind.server.rmi.RMIConnection.connect(RMIConnection.java : 2040)
at com.evermind.server.rmi.RMIConnection.connect(RMIConnection.java : 1884)
at com.evermind.server.rmi.RMIConnection.lookup(RMIConnection.java : 1491)
at com.evermind.server.rmi.RMIServer.lookup(RMIServer.java : 323)
at com.evermind.server.rmi.RMIContext.lookup(RMIConext.java : 106)
at com.evermind.server.administration.LazyResourceFinder.lookup(LazyResourceFinder.java : 59)
at com.evermind.server.administration.LazyResourceFinder.getEJBHome(LazyResourceFinder.java : 26)
at com.evermind.server.Application.createContext(Application.java: 653)
at com.evermind.server.ApplicationClientInitialContext.getInitialContext(ApplicationClientInitialContextFactory.java :179 )
at javax.naming.spi.NamingManager.getInitialContext(NamingManger.java : 246)
at javax.naming.InitialContext.getDefaultInitialCtx(InitialContext.java : 246)
at javax.naming.InitialContext.init(InitialContext.java : 222)
at javax.naming.InitialContext.<init>(InitialContext.java : 178)
at DemoClient.main(DemoClient.java : 23)
.ear file is copied into applications directory.
I have configured server.xml file like this
<application name="sampledemo" path="../applications/demos.ear" />
demos.ear file Contains following files
application.xml
demobean.jar
Manifest.mf
demobean.jar file contains following files
application-client.xml
Demo.class
DemoBean.class
DemoHome.class
ejb-jar.xml
jndi.properties
Mainifest.mf
Please give me your valuable suggestions. Which are shall i configure .
Thanks & Regards,
BadriHi Badri,
ApplicationClientInitialContextFactory is for clients which got deployed inside OC4J container..
For looking up EJB from a stand alone java client please use RMIInitialContextFactory..So please change ur code....
Also please check ur server.xml
Since you have specified your ejb domain as "sampledemo"
you have to use that domian only for look up..But it seems that you are looking up for "Demo" domain instead of "sampledemo" domain...So change your code to reflect that..
Code snippet for the same is :
Hashtable env = new Hashtable();
env.put("java.naming.provider.url", "ormi://localhost/sampledemo");
env.put("java.naming.factory.initial", "om.evermind.server.rmi.RMIInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, "guest");
env.put(Context.SECURITY_CREDENTIALS, "welcome");
Context ic = new InitialContext (env);
Hope this helps
--Venky -
Dependency inject a EJB 2.x bean with EJB3
Hi there
I have an old EJB3 2.x bean deployed on my server, that is registered in JNDI with the name "abc/xyz/ItemLookup_v35".
Now I wrote a EJB3 SFSB bean and I want to access the old bean using dependency injection. I tried it with the annotation
@EJB(mappedName = "abc/xyz/ItemLookup_v35")
private ItemLookupRemote itemRemote;but it wasn't working. How can I explicitly set the JNDI name of an old bean, that I want to lookup for?
Any help is appreciated!
Regards,
Stephan
Edited by: MasterRefactorer on Jun 27, 2008 7:31 AMYou can use @EJB to access 2.x Remote views, but the field type has to be the Home interface.
@EJB(mappedName = "abc/xyz/ItemLookup_v35")
private ItemLookupHome itemHome; -
Finding EJB from Application Client
When i tried to use lookup function using j2ee1.4 it was throwing an exception "NoInitialContextException".
So I stored Context and port information in System.Property and use them while creating an object of InitialContext. It is working fine.
But my problem is, we were not specifying these things with the earlier versions of j2ee. Is it a right way to get the reference of EJB or is there any other way to do it.
Thanx in Advance
SandeepYou can put all the necessary properties in jndi.properties file and put the file in an application classpath, i.e. :
jndi.properties file:
java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
java.naming.provider.url=t3://localhost:7001http://java.sun.com/j2se/1.4.2/docs/guide/jndi/spec/jndi/jndi.6.html
Message was edited by: akocic66
akocic66 -
Conditional dependency injection in EJB 3
Hi friends
I want to inject a session bean if a condition is true.
what can i do it ?
Message was edited by:
Saeed_ZarinfamHi Saeed,
There is no such capability in Java EE 5. If at deployment time the bean class and/or its associated
ejb-jar.xml has metadata that indicates injection, injection will take place. -
EJB 3.0 Why Dependency Injection doesn't work?
Hello Every body,
i have a serious problem with dependency injection with EJB 3.0. I have tried so many time to get the simple sun delivered samples ejb-Applications working in NetBeans IDE, but they don't. After importing in building the projects in NetBeans, i get a NullPointerException while trying to run them. Is there any body who have experience with this? What am i making wrong?
I searched for an answer since several days in google without any success. I have not found a single satisfactory explanation. I can't explain why even the examples in the java ee tutorials don't work.
Please, can somebody help? I would very greatful.
Cheers
flips
Here is an example of application (that don't work because the injection failed):
* This is the business interface for Confirmer enterprise bean.
@Remote
public interface Confirmer {
void sendNotice(String recipient);
@Stateless
public class ConfirmerBean implements Confirmer {
private static final String mailer = "JavaMailer";
private static Logger logger = Logger.getLogger(
"confirmer.ejb.ConfirmerBean");
@Resource(name = "mail/myMailSession")
private Session session;
/** Creates a new instance of ConfirmerBean */
public ConfirmerBean() {
public void sendNotice(String recipient) {
try {
Message message = new MimeMessage(session);
message.setFrom();
message.setRecipients(
Message.RecipientType.TO,
InternetAddress.parse(recipient, false));
message.setSubject("Test Message from ConfirmerBean");
DateFormat dateFormatter = DateFormat.getDateTimeInstance(
DateFormat.LONG,
DateFormat.SHORT);
Date timeStamp = new Date();
String messageText = "Thank you for your order." + '\n'
+ "We received your order on "
+ dateFormatter.format(timeStamp) + ".";
message.setText(messageText);
message.setHeader("X-Mailer", mailer);
message.setSentDate(timeStamp);
// Send message
Transport.send(message);
logger.info("Mail sent to " + recipient + ".");
} catch (MessagingException ex) {
ex.printStackTrace();
logger.info("Error in ConfirmerBean for " + recipient);
* @author ie139813
public class ConfirmerClient {
@EJB
private static Confirmer confirmer;
/** Creates a new instance of ConfirmerClient */
public ConfirmerClient() {
* @param args the command line arguments
public static void main(String[] args) {
String recipient = null;
if (args.length == 1) {
recipient = args[0];
} else {
recipient = "[email protected]";
try {
confirmer.sendNotice(recipient);
System.out.println("Message sent to " + recipient + ".");
System.exit(0);
} catch (Exception ex) {
ex.printStackTrace();
}Try rebooting your computer. I had something similar. I rebooted my computer and it finished the update. Good luck!
-
EJB 3.0 client side dependency injection
Hi,
I develop an EJB 3.0 based enterprise application using Sun Java System Application Server. The application includes a Swing based client to be launched via Java WebStart. The client has to access some of the EJBs. Is it possible to use dependency injection on client side (see the @EJB annotation) and if yes how do I set the properties for this?
The following snipped hopefully explains what I mean. The class FastEntry is a class of the Swing client. My question is how can I get the deviceSessionBean initialized?
public class FastEntry extends javax.swing.JFrame {
@EJB
private static DeviceSessionRemote deviceSessionBean;Kind regards,
MatthiasHi,
For callbacks and interceptors, you can look at this page : http://today.java.net/pub/a/today/2005/08/18/ejb3.html
For sending messages, I'd recommend to use JMS (if in clientSide), or EJB3 Message beans if in server side.
Hope that helps :) -
Dependency Injection Problem in EJB 3.0
Hello.
I've been trying to get an example of java dependency injection working in JBoss 4.0.5.GA. I've installed it with EJB 3.0 support.
The problem is that if I try to use the injected resource, I get a null pointer exception.
The example I'm trying is a very short and simple one. Shouldn't be hard to figure out what is going wrong. Here it goes:
[root]\src\hello\MessageServlet.java:
package hello;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.List;
import java.util.ListIterator;
import javax.naming.InitialContext;
import javax.annotation.*;
public class MessageServlet extends HttpServlet {
@Resource (mappedName="java:/DefaultDS")
javax.sql.DataSource ejb30DB;
public void init () throws ServletException {
public void service(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
boolean injectedLookingGood = false;
boolean notInjectedLookingGood = false;
try {
java.sql.Connection conn = ejb30DB.getConnection();
conn.close();
injectedLookingGood = true;
} catch(Exception e) {
e.printStackTrace();
try {
InitialContext ic = new InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource)ic.lookup("java:/DefaultDS");
java.sql.Connection conn = ds.getConnection();
conn.close();
notInjectedLookingGood = true;
} catch(Exception e) {
e.printStackTrace();
response.setContentType("text/html");
ServletOutputStream out = response.getOutputStream();
out.println("<html>");
out.println("<head><title>Hello World</title></head>");
out.println("<body>");
out.println("<h1>Hello World</h1>");
out.println("<form action=\"HelloWorld\" method=\"get\">");
out.print("Injected DataSource is looking ");
if(injectedLookingGood) {
out.println("good <br>");
else {
out.println("bad <br>");
out.print("Not-Injected DataSource is looking ");
if(notInjectedLookingGood) {
out.println("good <br/>");
else {
out.println("bad <br/>");
out.println("<input type=\"submit\" value=\"Test Some More\">");
out.println("</form>");
out.println("</body>");
out.println("</html>");
[root]\etc\META-INF\web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<display-name>HelloWorldWAR</display-name>
<servlet>
<display-name>HelloWorld</display-name>
<servlet-name>HelloWorldServlet</servlet-name>
<servlet-class>hello.MessageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/servlet/HelloWorld</url-pattern>
</servlet-mapping>
</web-app>
[root]\etc\META-INF\application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/j2ee" version="1.4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com /xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
<display-name>HelloWorld</display-name>
<description>Application description</description>
<module>
<web>
<web-uri>web-ejb3.war</web-uri>
<context-root>HelloWorld</context-root>
</web>
</module>
</application>
[root]\build.xml:
<project name="HelloWorld" default="all" basedir=".">
<!-- Name of project and version -->
<property name="proj.name" value="HelloWorld"/>
<property name="proj.version" value="1.0"/>
<!-- Global properties for thid build -->
<property name="src.dir" value="${basedir}/src"/>
<property name="build.dir" value="${basedir}/bin"/>
<property name="lib.dir" value="${basedir}/lib"/>
<property name="build.classes.dir" value="${build.dir}/classes"/>
<property name="build.jar.dir" value="${build.dir}/jar"/>
<property name="src.etc.dir" value="${basedir}/etc"/>
<property name="meta-inf.dir" value="${src.etc.dir}/META-INF"/>
<!-- The build classpath -->
<path id="build.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
<include name="**/*.zip"/>
</fileset>
</path>
<!-- Useful shortcuts -->
<patternset id="meta.files">
<include name="**/*.xml" />
<include name="**/*.properties"/>
</patternset>
<target name="prepare">
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes.dir}"/>
<mkdir dir="${build.jar.dir}"/>
</target>
<target name="compile" depends="prepare">
<javac destdir="${build.classes.dir}"
classpathref="build.classpath"
debug="on">
<src path="${src.dir}"/>
</javac>
</target>
<target name="package-web" depends="compile">
<war warfile="${build.dir}/jar/web-ejb3.war"
webxml="${meta-inf.dir}/web.xml">
<classes dir="${build.dir}/classes">
<include name="**/*Servlet.class"/>
</classes>
</war>
</target>
<!-- Creates an ear file containing the web client war. -->
<target name="assemble-app">
<ear destfile="${build.jar.dir}/HelloWorld.ear" appxml="${meta-inf.dir}/application.xml">
<fileset dir="${build.dir}/jar"
includes="*.war"/>
</ear>
</target>
<target name="clean">
<delete dir="${build.dir}" />
</target>
<target name="all">
<antcall target="clean" />
<antcall target="package-web" />
<antcall target="assemble-app" />
</target>
</project>
Any help would be apreciated.
Thanks in advance,
Hugo Oliveira
[email protected]Hello Ken.
I gess dependency injection is unnavailable in servlets as of this moment. I conducted another test using a session bean that injects and tests the DataSource and a servlet calling the session bean via a refference obtained from InitialContext. It worked OK.
Here's the code:
[root]/src/hello/MessageHandler.java:
package hello;
public interface MessageHandler {
public boolean testInjection();
[root]/src/hello/MessageHandlerBean.java:
package hello;
import javax.ejb.Stateless;
import javax.persistence.*;
import java.util.List;
import javax.annotation.*;
@Stateless
public class MessageHandlerBean implements MessageHandler {
@Resource (mappedName="java:/DefaultDS")
private javax.sql.DataSource ds;
public boolean testInjection() {
try {
java.sql.Connection conn = ds.getConnection();
conn.close();
return true;
} catch(Exception e) {
e.printStackTrace();
return false;
[root]/src/hello/MessageServlet.java:
package hello;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.List;
import java.util.ListIterator;
import javax.naming.InitialContext;
import javax.annotation.*;
public class MessageServlet extends HttpServlet {
public void init () throws ServletException {
public void service(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
boolean injectedLookingGood = false;
try {
InitialContext ic = new InitialContext();
MessageHandler mh = (MessageHandler)ic.lookup("HelloWorld/MessageHandlerBean/local");
injectedLookingGood = mh.testInjection();
} catch(Exception e) {
e.printStackTrace();
response.setContentType("text/html");
ServletOutputStream out = response.getOutputStream();
out.println("<html>");
out.println("<head><title>Hello World</title></head>");
out.println("<body>");
out.println("<h1>Hello World</h1>");
out.println("<form action=\"HelloWorld\" method=\"get\">");
out.print("Injected DataSource is looking ");
if(injectedLookingGood) {
out.println("good <br>");
else {
out.println("bad <br>");
out.println("<input type=\"submit\" value=\"Test Some More\">");
out.println("</form>");
out.println("</body>");
out.println("</html>");
[root]/etc/META-INF/application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/j2ee" version="1.4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com /xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
<display-name>HelloWorld</display-name>
<description>Application description</description>
<module>
<ejb>HelloWorld.ejb3</ejb>
</module>
<module>
<web>
<web-uri>web-ejb3.war</web-uri>
<context-root>HelloWorld</context-root>
</web>
</module>
</application>
[root]/etc/META-INF/web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>HelloWorldWAR</display-name>
<servlet>
<display-name>HelloWorld</display-name>
<servlet-name>HelloWorldServlet</servlet-name>
<servlet-class>hello.MessageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/servlet/HelloWorld</url-pattern>
</servlet-mapping>
</web-app>
[root]/build.xml:
<project name="HelloWorld" default="all" basedir=".">
<!-- Name of project and version -->
<property name="proj.name" value="HelloWorld"/>
<property name="proj.version" value="1.0"/>
<!-- Global properties for thid build -->
<property name="src.dir" value="${basedir}/src"/>
<property name="build.dir" value="${basedir}/bin"/>
<property name="lib.dir" value="${basedir}/lib"/>
<property name="build.classes.dir" value="${build.dir}/classes"/>
<property name="build.jar.dir" value="${build.dir}/jar"/>
<property name="src.etc.dir" value="${basedir}/etc"/>
<property name="meta-inf.dir" value="${src.etc.dir}/META-INF"/>
<!-- The build classpath -->
<path id="build.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
<include name="**/*.zip"/>
</fileset>
</path>
<!-- Useful shortcuts -->
<patternset id="meta.files">
<include name="**/*.xml" />
<include name="**/*.properties"/>
</patternset>
<target name="prepare">
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes.dir}"/>
<mkdir dir="${build.jar.dir}"/>
</target>
<target name="compile" depends="prepare">
<javac destdir="${build.classes.dir}"
classpathref="build.classpath"
debug="on">
<src path="${src.dir}"/>
</javac>
</target>
<target name="package-ejb" depends="compile">
<jar jarfile="${build.jar.dir}/HelloWorld.ejb3">
<fileset dir="${build.classes.dir}">
<include name="**/*.class"/>
</fileset>
<!--
<metainf dir="${meta-inf.dir}">
<include name="persistence.xml"/>
</metainf>
-->
</jar>
</target>
<target name="package-web" depends="compile">
<war warfile="${build.dir}/jar/web-ejb3.war"
webxml="${meta-inf.dir}/web.xml">
<!--
<fileset dir="web">
<include name="**/*"/>
</fileset>
-->
<!--
<webinf dir="dd/web">
<include name="jboss-web.xml"/>
</webinf>
-->
<classes dir="${build.dir}/classes">
<include name="**/*Servlet.class"/>
</classes>
</war>
</target>
<!-- Creates an ear file containing the ejb jars and the web client war. -->
<target name="assemble-app">
<ear destfile="${build.jar.dir}/HelloWorld.ear" appxml="${meta-inf.dir}/application.xml">
<fileset dir="${build.dir}/jar"
includes="*.ejb3,*.war"/>
</ear>
<!-- <delete file="${build.dir}/jar/web-ejb3.war"/>
<delete dir="${build.dir}/classes"/> -->
</target>
<target name="clean">
<delete dir="${build.dir}" />
</target>
<target name="all">
<antcall target="clean" />
<antcall target="package-ejb" />
<antcall target="package-web" />
<antcall target="assemble-app" />
</target>
</project>
Thanks,
Hugo Oliveira
[email protected] -
EJB 3.0 Application Client threw Remote nested exception
Hi All,
I came across the following EJBException message when trying to retrieve an Employee record (entity bean in EJB 3.0) after having successfully added it into EMPLOYEE table using stateless session bean:
*10/03/2009 8:53:14 PM com.sun.enterprise.appclient.MainWithModuleSupport <init>*
WARNING: ACC003: Application threw an exception.
javax.ejb.EJBException: nested exception is: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException: null; nested exception is:
java.lang.NullPointerException
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException: null; nested exception is:
java.lang.NullPointerException
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:243)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:205)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:152)
at com.sun.corba.ee.impl.presentation.rmi.bcel.BCELStubBase.invoke(BCELStubBase.java:225)
at ejb.__EmployeeRemote_Remote_DynamicStub.findEmployee(ejb/__EmployeeRemote_Remote_DynamicStub.java)
at ejb._EmployeeRemote_Wrapper.findEmployee(ejb/_EmployeeRemote_Wrapper.java)
at client.EmployeeApplicationClient.printEmployee(EmployeeApplicationClient.java:608)
at client.EmployeeApplicationClient.main(EmployeeApplicationClient.java:55)
Below is the code snippets of EmployeeApplicationClient.java:
public class EmployeeApplicationClient {
@EJB
private static EmployeeRemote employeebean1;
@EJB
private static EmployeeRemote employeebean2;
public EmployeeApplicationClient() {}
public static void main(String[] args)
EmployeeApplicationClient employee_application_client = new EmployeeApplicationClient();
employee_application_client.addEmployee(1, John, Smith);
employee_application_client.printEmployee(1);
public void addEmployee(int id, String firstname, String surname)
try {
Employee employee1 = new Employee();
employee1.setID(id);
employee1.setfirstname(firstname);
employee1.setsurname(surname);
employeebean1.createEmployee(employee1);
catch {.....}
public void printEmployee(int employee_id)
Employee employee2 = employeebean2.findEmployee(employee_id);
System.out.println("employee Id: " + employeebean2.getId());
System.out.println("employee firstname: " + employeebean2.getfirstname());
System.out.println("employee surname: " + employeebean2.getsurname());
}Using employeebean1/employeebean2 in printEmployee() did not make any difference.
The error message appears to indicate that I have incorrectly structured these methods.
The deployment of EmployeeBean was successful and employee1 is in EMPLOYEE table via SQL query.
I am using JDK1.6.07, Glassfish v2 with MySQL 5.0 and Netbeans 6.1 on Windows XP platform.
Any assistance would be greatly appreciated.
Thanks,
JackHi Ataraxisme,
Thank you for responding to this post.
This is a J2EE Application Client that was created and deployed along as an Netbeans EAR (both Application Client and EJB) project which uses resource injection as opposed to JNDI lookup.
I am trying to get employeeApplicationClient.java to work the same way as the following travelAgentApplicationClient.java example which has successfully retrieved its record record immediately after adding using resource injection:
public class TravelAgentClient {
@EJB
private static TravelAgentRemote travelagent;
public TravelAgentClient() {
public static void main(String[] args) {
TravelAgentClient client = new TravelAgentClient();
client.doTravelAgent();
public void doTravelAgent() {
try {
Cabin cabin_1 = new Cabin();
cabin_1.setId(1);
cabin_1.setName("Master Suite");
cabin_1.setDeckLevel(1);
cabin_1.setShipId(1);
cabin_1.setBedCount(3);
travelagent.createCabin(cabin_1);
Cabin cabin_2 = travelagent.findCabin(1);
System.out.println(cabin_2.getName());
System.out.println(cabin_2.getDeckLevel());
System.out.println(cabin_2.getShipId());
System.out.println(cabin_2.getBedCount());
......Thanks,
Jack -
EJB 3.0 Dependency Injection and reentrant Calls on SFSB
Hi there
I have a SFSB (Bean A) that injects another SFSB (Bean B) with the @EJB annotation. Now Bean A does reentrant-calls on Bean B, which is ok, because it just asks for the current state.
This results in a "javax.ejb.EJBTransactionRolledbackException: Illegal attempt to make a reentrant call to a stateful session bean from home: .....; nested exception is: javax.ejb.ConcurrentAccessException: Illegal attempt to make a reentrant call to a stateful session bean: ....."
Now I added a weblogic-ejb-jar.xml with the section:
<stateful-session-descriptor>
<allow-concurrent-calls>true</allow-concurrent-calls>
</stateful-session-descriptor>to enable reentrant calls on my SFSB. Unfortunatly this leads to problems with the DI, it simply doesnt work anymore!!! The message now is " java.lang.IllegalStateException: Cannot find object BeanBInterface with java:comp/env/ejb/BeanBInterface". Obviously the DI didn't work, the local variable isn't filled anmyore.
Is this a bug of WLS 10.0 MP1 or a feature? Should I open a bug report? Any tips a welcome!
StephanThere is currently no possiblity in Weblogic 10 server web layer to use Dependency Injection on any other component than the ones defined in web.xml s.a.:
- servlets
- listeners
- filters
See here:
http://e-docs.bea.com/wls/docs100/webapp/annotateservlet.html
A simple POJO class part of the web application (such as a Backing Bean in JSF or an Action in Struts for example) is not benefiting from DI.
Doesn't this make Weblogic 10 a NON JEE 5 compliant server?
Why was this restriction imposed?
And how is one supposed to use DI with a simple POJO class? Why this huge inconvenience? -
EJB 3.0 Dependency Injection in JSF ?
Hi,
I have a question about ejb 3.0 dependency injection in a JSF WebApp:
I Build successfully a Web Module (version 2.5) an EJB Module (version 3.0) and an EAR Module (Version 5.0). The EAR App can be deployed without errors on a Bea WebLogic Server 10.1. All modules are successfully deployed.
Inside the Web Module there is a Servlet which uses dependency injection to access the session EJB form the EJB Module. This works perfect.
Next I try to use the same EJB with dependency injection from the JSF Page via a backing bean. But when I try to access my JSP Page I got a Nullpointer Exception.
It seems that the Dependency Injection in the JSP App did not work?
Can anybody give me a hint what could be wrong?
Thanks
RalphThere is currently no possiblity in Weblogic 10 server web layer to use Dependency Injection on any other component than the ones defined in web.xml s.a.:
- servlets
- listeners
- filters
See here:
http://e-docs.bea.com/wls/docs100/webapp/annotateservlet.html
A simple POJO class part of the web application (such as a Backing Bean in JSF or an Action in Struts for example) is not benefiting from DI.
Doesn't this make Weblogic 10 a NON JEE 5 compliant server?
Why was this restriction imposed?
And how is one supposed to use DI with a simple POJO class? Why this huge inconvenience? -
How to run application client of an EJB application?
Hi,
My EJB application is deployed on websphere. I have written a small java client program to interact with an EJB which is working fine if I compile and run it in websphere studio environment.
However I am getting runtime exception when I tried to run it at command line.
RemoteConn.java
import java.util.Hashtable;
import com.deque.HelloJavaHome;
import com.deque.HelloJava;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.ejb.EJBHome;
import javax.ejb.EJBObject;
public class RemoteConn {
public static void main(String[] ar) throws Exception{
String name="Paruchuri!!";
String greeting = "";
try{
Hashtable env = new Hashtable();
//env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.ws.naming.util.WsnInitCtxFactory");
env.put(Context.PROVIDER_URL, "iiop://localhost:2809");
InitialContext initContext = new InitialContext(env);
Object obj = initContext.lookup("ejb/HelloJavaHome");
HelloJavaHome home = (HelloJavaHome) javax.rmi.PortableRemoteObject.narrow(obj, HelloJavaHome.class);
HelloJava remote = home.create();
greeting = remote.getGreeting(name);
catch(Exception e){
e.printStackTrace();
System.out.println("Greeting::"+ greeting);
I have set the application ejb client jar in the class path of client program.
The exception I am getting at runtime is
Exception in thread "main" java.lang.NoClassDefFoundError: com.ibm.CORBA.iiop.GlobalORBFactory
at com.ibm.ejs.oa.EJSORBImpl.class$(EJSORBImpl.java:44)
at com.ibm.ejs.oa.EJSORBImpl.initializeORB(EJSORBImpl.java:195)
at com.ibm.ejs.oa.EJSClientORBImpl.(EJSClientORBImpl.java:93)
at com.ibm.ejs.oa.EJSClientORBImpl.(EJSClientORBImpl.java:65)
at com.ibm.ejs.oa.EJSORB.init(EJSORB.java:385)
at com.ibm.ws.naming.util.Helpers.getOrb(Helpers.java:284)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:369)
at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:112)
at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:422)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:143)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at RemoteConn.main(RemoteConn.java:38)
Initially I thought I shuold set some jar file of websphere in the classpath of client. But I did not find such a jar containing the above class in websphere studio.
Basically the error is generated at the below statement at runtime.
Object obj = initContext.lookup("ejb/HelloJavaHome");
The only difference I discovered was that the client application has a descriptor file (application-client.xml ) available to it when it ran in websphere studio,. I guess the same META-INF should be provided to client when it runs at command line.
Right now I am not using any client descriptor file to run the client program. If the above error is due to not supplying META-INF to the client application, how should I make this folder available to client at runtime?
I greatly appreciate if I could get help ASAP.
ThanksHey got what is going on. In order to invoke EJB, deployed on WebSpehre App Server, from application client we need to install either WebSphere Application Pluggable Client or WebSphere Thin client on the workstation. Pluggable client is a wrapper to SUN JRE where as Thin Client uses IBM JRE.
-
Dependency injection across enterprise applications is possible?
Hi All ,
I am working on EJB3.0. I want to know if we can use dependency injection across application?
I have
1. jpadc having all JPA classes and 1 jpaAppl enterprise application having only jpadc
2. session1dc and session1Appl enterprise application for session1dc
3. session2dc and session2Appl enterprise application for session2dc
I want to use jpa classes and sesisonbean classes from jpadc and session2dc respectively
inside session2dc. is it possible? i tried but i am not able to d odependency injection
Please let me know if this is possible?
Thnx in advance
Regards
KavitaHi Kavita,
Yes, you can use dependency injection. For more information, refer to this document:
http://help.sap.com/saphelp_nwce711/helpdata/en/44/bf6e9344751eaae10000000a1553f6/frameset.htm
If you need information related to the JPA part, read this:
http://help.sap.com/saphelp_nwce711/helpdata/en/46/307a2a50094f09e10000000a114a6b/frameset.htm
Best regards,
Ekaterina -
ADFc 11g: EJB Dependency injection
Hello everyone,
I'm using a managed bean which references a stateless session EJB 3.0:
public class MyManagedBean {
@EJB
private SessionEJB ejb;
}If the bean is managed by JSF (ie. is registered in faces-config) then the EJB is injected correctly, but if the EJB is managed by ADF (ie. is registered in adfc-config) then there is no dependency injection. Does anybody know why this is so, and if there is a clean solution to the problem?
Searching the forum, Duncan Mills recommends a bean managed with faces-config in which the EJBs are injected, and then use managed properties to inject those EJBs in the ADF-managed beans.
Re: Accessing session beans from a managed bean
Is there a better/simpler solution?
Thanks!
Juan ManuelThank you.
The link helped.
The one thing i did was created a remote interface for the ejb, which showed up in jndi and then used spring DI to inject a reference to the EJB from jndi.
Will using a remote interface (instead of a local interface) cause performance issues? -
When to use @Resource and when to use @EJB for dependency injection
Hi,
When do you use
@Resource and when do you use @EJB for dependency injection?
ThanksCaptain obvious: Use @EJB for injection of EJBs, and @Resource for everything else.
There was a discussion about this very topic quite recently, perhaps you can find it through the search.
Maybe you are looking for
-
Authorization Issue while running a report
Hi Experts, We are facing strange issue in authorizations while runnung a report. When we givel '*' company code access to the users they are able to run the report. When we give one single company code specific access to the users they get error mes
-
I have a problem with the UML support that I need help with. I have an existing Netbeans project and created a UML project reversed from existing Java sources (or something like that). I have a source tree like this: com.test.packagea
-
My iPod Classic was stolen and returned to me by police but now it "cannot be synced because it cannot be written to or read from". I noticed the thief had changed the format to "windows" but I have restored it and still get the same message.
-
Home Button Stopped Working!
I have an iPod touch 4th gen. and my home button has stopped working? how can i fix it? or can the apple store fix it?
-
Hi, In ISA web application, i need display a new data at Order Status dispaly. The jsp page is orderstatusdetail.jsp which gets data from standard isa bapi BAPISDORDER_GETDETAILEDLIST ( i got the bapi name from isaruntime.log file ) I am getting mod