How to inject implementation of a interface

@Local public interface MyInterface{ //methods } @Stateless(name="myimpl") public class MyImpl implements MyInterface{ //methods and etc... } @RequestScoped public class MyResource{ @EJB(beanName="myimpl") MyInterface obj; //other stuff }
This is how to inject a implementation from a interface. If the interface is not annotated even if u try to inject the MyImpl it will not be possible because CDI searchs for the interface that MyImpl implements.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.