ClassCastException when casting to the same class

前端 未结 11 843
小蘑菇
小蘑菇 2020-11-22 07:09

I have 2 different Java projects, one has 2 classes: dynamicbeans.DynamicBean2 and dynamic.Validator.

On the other project, I load both of

11条回答
  •  鱼传尺愫
    2020-11-22 07:57

    I had the same issue on a wildfly EJB, The EJB was returning a list of Objects and has an remote and a local interface. I used the Local interface by mistake what was working just fine up until the point you try to cast the objects in the list.

    Local/Remote interface:

    public interface DocumentStoreService {
    
        @javax.ejb.Remote
        interface Remote extends DocumentStoreService {
        }
    
        @javax.ejb.Local
        interface Local extends DocumentStoreService {
        }
    

    The EJB bean:

    @Stateless
    public class DocumentStoreServiceImpl implements DocumentStoreService.Local, DocumentStoreService.Remote {
    

    The correct spring wrapper around the EJB:

    
        
        
        
    
    

    Note the $Remote, You can change this to $Local and it will find the Local interface just fine, and also execute the methods without any issue (from a separate application on the same container), but the model objects are not marshaled and are from a different class loader if you use the local interface by mistake.

提交回复
热议问题