1 Reply Latest reply on Jan 26, 2012 12:11 PM by Bruno Santos

    Several issues with injection in AS 7 modules

    Bruno Santos Newbie

      Guys, I need some help here!


      I'm writting my own AS 7 module that happens to be a (login module) and I'm having some issues getting injection to work.


      In a pojo the following does not work:



      private MyLocalBean localBean;



      private MyLocalBean localBean;


      and the same happens with persistance context:



      private EntityManager entityManager;



      private EntityManager entityManager;


      How can I access these beans (my beans and EntityManager) within a module?

      In previous versions of JBoss I could get ejb's in a login module through a JNDI lookup for "ear_name/BeanInterface/local".


      Also, when @Entity beans are loaded from a module one would expect to have the necessary tables generated in the same way that this happens if these beans are loaded from within the ear, no?



        • 1. Re: Several issues with injection in AS 7 modules
          Bruno Santos Newbie

          Ok, even though it is not a solution for a fully modular login module, I was able to get to a bean by JNDI with the help of AS7 CLI /subsystem=naming:jndi-view command.


          This solution will work for my application but it won't be fully modular (reusable) because the interface will be in the module but actually implementation of the bean will have to be in the ear or the bean will never be loaded/detected by the EJB container.


          If we use the login module example provided by Anil (see here) and we add a new interface to the module package such as:


          public interface ITest {


              public String foo();




          To the ear application we add the implementation such as:




          public class TestBean implements ITest {



              public String foo() {

                  return "Hello foo!";





          then we can access it through login module by using the following JNDI lookup:


          private ITest iTest;




          InitialContext ic;

          try {

              ic = new InitialContext();

              iTest = (ITest) ic.lookup("java:global/ear_name_only/my.jar/TestBean");

          } catch (NamingException e) {

              // do whatever...





          This works but I was hopping that one could inject any bean in the LoginModule AS7 module.

          This is only a partial solution since it does not offer full modularity as it would be expected and because of this I do not think this is the answer to the original issue.


          If someone has any better ideas on how to enable beans within a AS7 module and inject then within pojo's of that same module, please share.


          Is there any heavy weight JBossian that could shed some light on the issue?



          1 of 1 people found this helpful