I am new to Java EE and am using JBoss 7 to create my first project. I have an EAR project, an EJB project, WEB project and a JPA project in my workspace. The ejb created in the EJB project wants to use an ejb created in the JPA project. It all compiles fine, however when I deploy the EAR project I get the following exception and the deployement fails. Here is the main exception cause.
JBAS014544: No EJB found with interface of type 'com.kohlisoft.stockmanagement.jpa.service.StockManagementBeanJpa' for binding com.kohlisoft.stockmanagement.ejb.main.StockManagementService/sms
I suspect that the EJB project is not able to look at the class in jpa jar.
I have gone though various links to sort it out but no help. Based on few suggestions I have modified it but still no joy. 1. I checked the structure and the JPA project is going under the lib folder in .ear. 2. Updated the EJB project's manifest file to add the dependeny to the jpa jar.
I would really appreciate any help here.
The EJB in the JPA project.
@Stateless
@LocalBean
public class StockManagementBeanJpaBean implements StockManagementBeanJpa {
@PersistenceContext(unitName="StockManagement")
private EntityManager em;
The EJB in the EJB project which uses it:
@Stateless
@LocalBean
public class StockManagementService implements StockManagementServiceLocal {
@EJB
StockManagementBeanJpa sms;
...
EJB Project MANIFEST file.
Manifest-Version: 1.0
Class-Path: StockManagement-ejbClient.jar
Dependencies: lib/StockManagement-jpa.jar
Here is the structure of the .jars and .war in .ear.
.ear
|____ ejb.jar
|
|____ ejbClient.jar
|
|____ web.war
|
|____ /lib
|
| ____ jpa.jar
|
| ____ all other jars related to derby client, hibernate, jta etc.
Let me know if any other files are required.
Your file structure looks alright.
So, where is the problem ?
@Localbean
should be used inside your EJB bean only when your EJB is not extending interface. @Local
can be used for interface and then extending your EJB with the interface or using @Local
straingh inside your no-interface EJB. But @Localbean
is only used for no-interface EJB. So, what you are doing is not right.
Since you are extending interface, do as below:
Interface
@Local
public interface StockManagementBeanJpa
{
....
}
EJB
@Stateless
public class StockManagementBeanJpaBean implements StockManagementBeanJpa
{
....
}
Do this for all EJBs.
I want to point out 1 more thing that @Local
will work in your case because you are calling EJBs from the same application (same EAR). This will not work in the case of cross application call(different EAR, WAR ...) or remote client calling your EJB. In this case, you will need @Remote
.
In my case I accidentally had these imports in the EJB after some copy-pasting:
import javax.ejb.*;
import javax.inject.Singleton;
The EJB looked like this:
@Singleton
public class MyService {
Maven build went thru but the class was not deployed as EJB. After removing import javax.inject.Singleton;
it worked fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With