2 Replies Latest reply on Sep 10, 2015 8:10 PM by jonasventure

    Arquillian Spring Autowire NULL

    jonasventure

      I've got a relatively simple test case in which I'm trying to inject the ApplicationContext from Spring.  I have tried with the class annotated thusly:

       

       

      @ContextConfiguration(classes = {RESTClientConfig.class})

       

       

      and thusly:

       

       

      @SpringAnnotationConfiguration(classes = {RESTClientConfig.class})

       

       

       

       

      But in both cases the injected Bean from the RESTClientConfig.class ends up being null.  I've also tried injecting the ApplicationContext.  The configuration is all javaconfig. 

       

       

      The injection works properly with: SpringJUnit4ClassRunner.class

       

       

      Also, the appropriate pom dependencies are there (the two spring extension deps for arquillian for SpringAnnotationConfiguration, etc.).

       

       

      @RunWith(Arquillian.class)

      //@RunWith(SpringJUnit4ClassRunner.class)

      //@ContextConfiguration(classes = {RESTClientConfig.class})

      @SpringAnnotationConfiguration(classes = {RESTClientConfig.class})

      public class SimpleControllerTest {

        @Autowired

        private RestTemplateBean restTemplateBean;

       

       

        @Autowired

        private RestTemplate restTemplate;

       

       

        @Autowired

        private ApplicationContext context;

       

       

       

       

        @Test

        public void contextStartup() {

          assertNotNull(context);

          assertNotNull(restTemplate);

          assertNotNull(restTemplateBean);

        }

       

       

       

       

      }

        • 1. Re: Arquillian Spring Autowire NULL
          jonasventure

          I should add that all of my configuration is done with javaconfig:

          public class AppInitializer implements WebApplicationInitializer {

            @Override
            public void onStartup(ServletContext container) throws ServletException {

             WebApplicationContext context = getContext();

            container.addListener(new ContextLoaderListener(context));

           

            ServletRegistration.Dynamic dispatcher = container.addServlet("DispatcherServlet",

             new DispatcherServlet(context));

            dispatcher.setLoadOnStartup(1);

            dispatcher.addMapping("/");

            }

           

            private AnnotationConfigWebApplicationContext getContext() {

            AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();

            context.register(AppConfig.class, SpringMvcConfig.class);

             return context;

            }

          }

          • 2. Re: Arquillian Spring Autowire NULL
            jonasventure

            Just to add even more:

            @RunWith(Arquillian.class)

            @ContextConfiguration(classes = {RESTClientConfig.class})

             

            The ContextConfiguration is not setting up the ApplicationContext as it should.  The autowired components are all null.  Is this not supported while using arquillian in client mode?