Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cz.pfreiberg.test.ejb.session.TestSessionEJBLocal;
- import javax.enterprise.inject.Produces;
- import javax.naming.InitialContext;
- import javax.naming.NamingException;
- public class EJBProvider {
- public EJBProvider() {
- }
- /**
- * Now you can use @Inject for this EJB across your application.
- * Example: @Inject TestSessionEJBLocal testEJB;
- */
- @Produces
- public TestSessionEJBLocal getTestSessionEJBLocal() {
- return jndiLookup("java:global/TEST/TestSessionEJB!cz.pfreiberg.test.ejb.session.TestSessionEJBLocal",
- TestSessionEJBLocal.class);
- }
- private <T> T jndiLookup(String name, Class<T> type) {
- try {
- InitialContext ctx = new InitialContext();
- return type.cast(ctx.lookup(name));
- } catch (NamingException e) {
- String errorMessage = "Error during JNDI lookup for " + name;
- throw new RuntimeException(errorMessage, e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement