0 Replies Latest reply on Sep 6, 2013 9:53 AM by Koka Kokovoj

    Injecting Spring MVC Controller from .war included in the .ear into Arquillian test

    Koka Kokovoj Newbie

      I have a large .ear that consists of multiple .jars and multiple .war files that I am deploying into JBoss. I want to do end-to-end testing on one of the .wars' Controllers using spring-test-mvc framework, and hence need mvc Controllers from that .war @Autowired into my Arquillium test class. The .war in question has a servlet named "myservlet" in its web.xml (<servlet-name>myservlet</servlet-name>, and that's what I am using in SpringWebConfiguration below. The .ear (including the .war that I need to test) gets successfully deployed to JBoss, however, the Controller class is never injected and hence remains null.

      I am using arquillian-jbossas-managed-4.2.


      My test class looks like this :


      @SpringWebConfiguration(servletName = "myservlet")


      public class AqruilliumTest {



          private MyController myController;



          public static Archive createDeployment() {

                // Create an Archive from the existing .ear build on the file system (not manually constructed in this method)

                EnterpriseArchive ear = ShrinkWrap

                  .create( ZipImporter.class, "myLarge.ear" )

                  .importFrom( new File( "/Users/kokovoj/EarAndItsVariousComponents/An-Overall-EAR-folder/myLarge.ear" ) )

                  .as( EnterpriseArchive.class );

              System.out.println( ear.toString( true ) );

              return ear;





          public void controllerInjected() throws Exception {

              System.out.println( "--->>myController [" + myController + "]" );

              assertNotNull( myController );



      Questions :


      1. Is there a requirement / assumption that when using @SpringWebConfiguration, @Deployment public static Archive createDeployment() method MUST return a WebArchive for spring injections to work ? I am returning an EnterpriseArchive so is that the reason it does NOT work for me; is there a workaround for making this work for .ear ?


      2. In @Deployment public static Archive createDeployment() method I am not constructing the .ear manually, but rather using an existing .ear on the file system. Is there a requirement / assumption that archive must be constructed manually through code (and not use an existing archive from the file system) for spring injections to work ?