title: How to autowire service in another module?
body: <p>I am working on application which contains few sub modules. On one of these modules I have service with header like this:</p>
  
  <pre><code>@Transactional
  @Service("mySimpleService")
  public class MySimpleServiceImpl implements MySimpleService {}
  </code></pre>
  
  <p>On the another module I have a controller in which I would like to use one of the MySimpleService method. So I have something similar to this:</p>
  
  <pre><code>@Controller
  public class EasyController {    
  
      @Autowired
      private MySimpleService mySimpleService;
  
      @RequestMapping("/webpage.htm")
      public ModelAndView webpage(@RequestParam,
                                  @RequestParam,
                                  HttpServletRequest request,
                                  HttpServletResponse response) {
          ModelAndView mav = new ModelAndView(”webpage”);
          mav.addObject(”name”, mySimpleService.getObject());
          return mav;
      }
  }
  </code></pre>
  
  <p>On the line <code>mav.addObject(”name”, mySimpleService.getObject());</code> I am getting <code>NullPointerException</code>. I don't know why. I am not getting error similar to <code>Could not autowire field</code> but only <code>NullPointerException</code>.</p>
  
  <p>I have also created my own interceptor in this way to check some another ideas in my task:</p>
  
  <pre><code>public class CustomInterceptor extends HandlerInterceptorAdapter {
  
      @Autowired
      private MySimpleService mySimpleService;
  
      @Override
      public boolean preHandle(HttpServletRequest request, 
                               HttpServletResponse response,
                               Object handler)
                               throws Exception {         
          request.setAttribute("attr", mySimpleService.getAttribute());
          return true;
      }    
  }
  </code></pre>
  
  <p>This interceptor is of course declared in dispatcher servlet. In my logs I can see <code>NullPointerException</code> at line: <code>request.setAttribute("attr", mySimpleService.getAttribute());</code>. So this is exactly problem with getting access to service from another application module.</p>
  
  <p>How can I achieve this?</p>
  
  <p>I have heard about ideas like building EJB with my service and share it using <code>JNDI</code> or using Maven - copy folder with my service to target module during building application. I have tried to do the second option but it isn't working and I can't check if the coping was successful. Is possible to check Maven based solution? Do you have another suggestions?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>This is component scaning from target module dispatcher servlet:</p>
  
  <pre><code>&lt;context:component-scan base-package="my.package.target.module.controller" annotation-config="false"/&gt;
  </code></pre>