WELD-001408 Unsatisfied dependencies when injecting EJBs that implement interfaces

后端 未结 3 1119
孤独总比滥情好
孤独总比滥情好 2020-12-28 19:22

Here is the situation.

I\'ve got the following interfaces:

public interface Parent { }
public interface ChildOne extends Parent { }
public interf         


        
相关标签:
3条回答
  • 2020-12-28 20:16

    Better late than never:

    Annotating the SLSB aditionally with @LocalBean works for me with JBoss AS 7.1.1. I don't like the idea of creating the interface for no added value.

    Using your example:

    @Stateless
    @LocalBean
    public class FirstBean implements ChildOne { }
    
    @Stateless
    @LocalBean
    public class SecondBean implements ChildTwo { }
    
    0 讨论(0)
  • 2020-12-28 20:18

    Have you tried using @EJB annotation rather then the CDI @inject annotation?

    E.g.

    @Named
    @SessionScoped
    public class TestController implements Serializable {
    
        @EJB
        private FirstBean firstBean;
    
        @EJB
        private SecondBean secondBean;
    }
    
    0 讨论(0)
  • 2020-12-28 20:20

    I just played around with your construct, read a bit of the weld docu and found out the following.

    You are using EJBs that implement an interface, so the no-interface view is not possible anymore (obviously), but you are trying to directly access the implementation. As soon as you declare it as an EJB you have to keep in mind the conventions. So, if you define an interface you have to use it to get access to the EJB. Changing it to the following, should work out:

    @Inject
    private ChildOne firstBean;
    

    Accessing the implementation even though an interface is defined is just possible for plain CDI Managed Beans (classes without the @Stateless/@Stateful annotations). So get rid of your annotation and it will work out.

    Just for your information, if you are using Glassfish. If you stick to your EJBs and try to access the parent interfaces method you will run into this bug / exception.

    0 讨论(0)
提交回复
热议问题