1 2 Previous Next 17 Replies Latest reply on Apr 20, 2012 5:45 PM by suikast42 Go to original post
      • 15. Re: Dependency Injection won't work
        suikast42

        Hi Vineet,

         

        I assume that. I have allready a very dynamic Servicelocator so I can use that. In some cases the DI is not enough for our usecase. But I nothing will be work over DI. @PersistenceContex or @Rescource. Both of then don't work as well. I'm very confused.

        • 16. Re: Dependency Injection won't work
          suikast42

          Hi it's me again,

           

          it seems so that the DI won't work in an EAR deployment like in a WAR.

           

          I try the deployment shown below:

           

          public static EnterpriseArchive createTestArchive(Module testModule, Class<?>... additionalClasses){

              // Get needed Properties

              String versionbase = SystemPropertiesTestConstants.VERSION_BASE.getValue();

              String wmsear = SystemPropertiesTestConstants.WMS_EAR.getValue();

              String testModuleName = testModule.getModuleName() + "-" + versionbase + ".jar";

              // Retrieve the EAR file

              EnterpriseArchive ear = DependencyResolvers

                  .use(MavenDependencyResolver.class)

                  .artifact(wmsear)

                  .resolveAs(EnterpriseArchive.class).iterator().next();

           

              // EJB Jar with my testcase

              JavaArchive testModuleJar = ear.getAsType(JavaArchive.class, testModuleName);

              ear.delete(testModuleName);

              testModuleJar.addClasses(additionalClasses);

           

              ear.addAsModule(testModuleJar);

           

              return ear;

            }

           

          I get my EAR which is deployed in my local repo and replace it by adding my testcase in my EJB jar. The deployment is correct. I can verify this by adding the folowing property in my arquillan.xml

           

          <engine>

                  <property name="deploymentExportPath">target/</property>

          </engine>

           

          Everything works fine but the DI not as I want.

          • 17. Re: Dependency Injection won't work
            suikast42

            Hi guys,

             

            I think I didn't understood the arquillian apprroach. So my testcase is not an EJB. But by adding a beans.xml I can make it to a CDI bean where I can inject almost everything what I need. It was painfull but I learn it .

             

            So I changed my helper method for deployment as shown below:

             

              public static EnterpriseArchive createTestArchive(Class<?>... additionalClasses){

                String earMvnString= getMyEARString();

             

                JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "additionalClasses.jar")

                    .addClasses(additionalClasses).addAsResource(EmptyAsset.INSTANCE, "beans.xml");

             

                return DependencyResolvers

                    .use(MavenDependencyResolver.class)

                    .artifact(earMvnString)

                    .resolveAs(EnterpriseArchive.class).iterator().next()

                    .addAsLibrary(jar);

              }

             

            That rocks as I want.

            1 2 Previous Next