EJB Bindings - Class Cast Exception

Discussion in 'Java' started by micanti, Sep 21, 2017.

  1. micanti


    Sep 21, 2017
    Likes Received:

    i'm having an issue with EJB bindings which i can not resolve. To make it short, i have one project which is deployed several times (political manner), so i do have EJBs with the same name.
    I found 2 solutions, 1) defining a custom property on the JVM (which is not allowed internally) for long-form names, and 2) defining a binding file "ibm-ejb-jar-bnd.xml".

    I have tried to replicate what this file does, and "hard code" the bindings directly on the application instance. While accessing the context-root, i get a ClassCastException :

    DefaultDispat E com.opensymphony.xwork2.util.logging.commons.CommonsLogger error Exception occurred during processing request: Cannot cast class my.project.ejb.service.EJSLocal0SLCartService_14538494 to interface my.project.ejb.service.ICartService
    java.lang.ClassCastException: Cannot cast class my.project.ejb.service.EJSLocal0SLCartService_14538494 to interface my.project.ejb.service.ICartService
    at java.lang.Class.cast(Class.java:2632)

    To distinguish between the instances that will be installed, i set a variable during compiling with Maven. So, the bindings will be adapted.

    public interface ICartService {

    public class CartService implements ICartService{
    private IAuditTrailService auditTrailSvc; // Other EJB

    I do EJB injection. Can not use InitialContext as the bindings will be different from instance to instance.

    binding file "ibm-ejb-jar-bnd.xml":
    <?xml version="1.0" encoding="UTF-8"?>
    xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-bnd_1_0.xsd"

    <session name="CartService" simple-binding-name="ejb/app1/ICartService"/>

    I'm using EJB 3.1, Java 7, WAS 8.5.

    Can somebody help me out ?

    (I can change the application like i want, but do not have the possibility to change any configuration on the production server.)

    Thanks !
    micanti, Sep 21, 2017
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.