This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error while doing DI in statefull session bean

 
rachna jain
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey All

While writing statefulsession bean and invoking statelesbean method through DI facing issues

Please help


remote interface
package by.iba.ejb;

import javax.ejb.Remote;

@Remote
public interface StatefulCalculator {

public double add(double a);
public double subtract(double a);
public double multiply(double a);
public double divide(double a);
public void clean();

public void turnOff();
}






package by.iba.ejb;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.EJB;
import javax.ejb.Stateful;
import by.iba.ejb.StatefulCalculator;





public @Stateful class StatefulCalculatorBean implements StatefulCalculator {

@EJB
private StatelessCalculatorRemote calculator;

double register = 0;
public double add(double a) {
// TODO Auto-generated method stub

register=calculator.add(register, a);
return register;
}

public void clean() {
// TODO Auto-generated method stub
register = 0;
}

public double divide(double a) {
// TODO Auto-generated method stub
register = calculator.divide(register, a);
return register;
}

public double multiply(double a) {
// TODO Auto-generated method stub

register=calculator.multiply(register, a);
return register;
}

public double subtract(double a) {
// TODO Auto-generated method stub

register=calculator.subtract(register, a);
return register;
}

public void turnOff() {
System.out.println("[StatefulCalculatorBean] Good bye ! I gotta split !");
}

@SuppressWarnings("unused")
@PostConstruct
private void afterCreated() {
System.out.println("[StatefulCalculatorBean] PostConstruct callback !");
}

@SuppressWarnings("unused")
@PreDestroy
private void beforeRemoved() {
System.out.println("[StatefulCalculatorBean] PreDestroy callback !");
}

}

------STATELESSBEAN WHOSE METHODS I AM CALALING FROM STAEFUL BEAN METHODS-----

package by.iba.ejb;

import javax.ejb.Stateless;



/**
* Session Bean implementation class StatelessCalculator
*/
@Stateless

public class StatelessCalculator implements StatelessCalculatorRemote{
/**
* Default constructor.
*/
public StatelessCalculator() {
// TODO Auto-generated constructor stub
}

public double add(double a, double b) {
// TODO Auto-generated method stub
return a+b;
}

public double divide(double a, double b) {
// TODO Auto-generated method stub
if (b == 0.0) {
throw new javax.ejb.EJBException("Divide by zero error !");
}
return a / b;
}

public double multiply(double a, double b) {
// TODO Auto-generated method stub
return a*b;
}

public double subtract(double a, double b) {
// TODO Auto-generated method stub
return a-b;
}

}



error on console


12:44:24,808 INFO [Ejb3Deployment] EJB3 deployment time took: 76
12:44:24,812 WARN [EJBHandler] IGNORING DEPENDENCY: unable to find @EJB from interface only by.iba.ejb.StatelessCalculator in ejb-jar.xml of StatefulCalculatorBeannot used by any EJBs
12:44:24,813 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=Calculator1.jar,name=StatefulCalculatorBean,service=EJB3 with dependencies:
12:44:24,823 WARN [ServiceController] Problem starting service jboss.j2ee:jar=Calculator1.jar,name=StatefulCalculatorBean,service=EJB3
java.lang.RuntimeException: could not resolve global JNDI name for @EJB for container StatefulCalculatorBean: reference class: by.iba.ejb.StatelessCalculator ejbLink: not used by any EJBs
at org.jboss.injection.EjbEncInjector.inject(EjbEncInjector.java:88)
at org.jboss.ejb3.EJBContainer.start(EJBContainer.java:466)
at org.jboss.ejb3.SessionContainer.start(SessionContainer.java:121)
at org.jboss.ejb3.stateful.StatefulContainer.start(StatefulContainer.java:91)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.jboss.ejb3.ServiceDelegateWrapper.startService(ServiceDelegateWrapper.java:102)
at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
at $Proxy0.start(Unknown Source)
at org.jboss.system.ServiceController.start(ServiceController.java:417)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy123.start(Unknown Source)
at org.jboss.ejb3.JmxKernelAbstraction.install(JmxKernelAbstraction.java:96)
at org.jboss.ejb3.Ejb3Deployment.registerEJBContainer(Ejb3Deployment.java:281)
at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:328)
at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:91)
at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
at $Proxy0.start(Unknown Source)
at org.jboss.system.ServiceController.start(ServiceController.java:417)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy43.start(Unknown Source)
at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:449)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
at org.jboss.ws.integration.jboss.DeployerInterceptor.start(DeployerInterceptor.java:92)
at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy44.start(Unknown Source)
at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy6.deploy(Unknown Source)
at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:610)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:274)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:225)
12:44:24,824 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=Calculator1.jar,name=StatelessCalculator,service=EJB3 with dependencies:
12:44:24,831 INFO [EJBContainer] STARTED EJB: by.iba.ejb.StatelessCalculator ejbName: StatelessCalculator
12:44:24,837 INFO [EJB3Deployer] Deployed: file:/C:/Program Files/jboss-4.0.5.GA/server/default/deploy/Calculator1.jar
12:44:24,840 ERROR [URLDeploymentScanner] Incomplete Deployment listing:

--- MBeans waiting for other MBeans ---
ObjectName: jboss.j2ee:jar=Calculator1.jar,name=StatefulCalculatorBean,service=EJB3
State: FAILED
Reason: java.lang.RuntimeException: could not resolve global JNDI name for @EJB for container StatefulCalculatorBean: reference class: by.iba.ejb.StatelessCalculator ejbLink: not used by any EJBs

--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
ObjectName: jboss.j2ee:jar=Calculator1.jar,name=StatefulCalculatorBean,service=EJB3
State: FAILED
Reason: java.lang.RuntimeException: could not resolve global JNDI name for @EJB for container StatefulCalculatorBean: reference class: by.iba.ejb.StatelessCalculator ejbLink: not used by any EJBs




 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Have you tried the add an beanName element to the @EJB annotation which you use on the field to be injected?
Example:

Best wishes!
 
rachna jain
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey

Yes i tried it remained the same
 
rachna jain
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

i am instantiating a varibale of type remote interface not bean type is it correct?and giving name of bean
but fatre giving name also i didnt work i tried it earlier also

@EJB(beanName="StatelessCalculator")
private StatelessCalculatorRemote calculator;

Thanks
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Yes, the type of the instance variable should be that of the remote business interface.
However, what you want injected into the instance variable is a reference to the EJB with the name specified by the beanName field.
Best wishes!
 
rachna jain
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ivan it worked fine
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic