title: Spring boot jar does not detect beans defined in dependent modules
body: <p>I have spring boot application which runs perfectly when I run the runnable <code>Application</code> class of Spring boot from my Intellij locally. </p>
  
  <p>My module <code>PRESENT</code> is dependent on another module <code>OLDER</code>. So I added B as a dependency in pom.xml of <code>PRESENT</code>.</p>
  
  <p>main parts of my <code>pom.xml</code> are :</p>
  
  <pre><code>&lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.2.4.RELEASE&lt;/version&gt;
  &lt;/parent&gt;
  
  &lt;dependency for Module OLDER&gt;
  
  
  &lt;plugin&gt; 
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;               
      &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>I have few beans in <code>beans.xml</code>(in Module PRESENT), so I imported <code>app-context.xml</code>(which has all beans for Module OLDER) in <code>beans.xml</code>.</p>
  
  <pre><code>  &lt;beans xmlns="http://www.springframework.org/schema/beans" ...&gt;
        &lt;import resource="classpath:/app-context.xml"/&gt;
        //more beans
    &lt;/beans&gt;
  </code></pre>
  
  <p>I have a Service <code>ThreadService</code> in <code>Module OLDER</code>, in one of the controllers in <code>MODULE PRESENT</code> I have autowired this <code>ThreadService</code>. When I run locally it works fine but when I create a jar it does not detect the <code>app-context.xml</code> and gives the following exception</p>
  
  <pre><code>org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:/app-context.xml]
  Offending resource: class path resource [messageBeans.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [app-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [app-context.xml] cannot be opened because it does not exist
          at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
          at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
          at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)
          at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:235)
          at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:186)
          at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:171)
          at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:144)
          at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:100)
          at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:510)
          at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392)
          at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
          at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
          at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
          at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
          at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
          at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromImportedResources(ConfigurationClassBeanDefinitionReader.java:347)
  </code></pre>
  
  <p>I have searched a bit and changed </p>
  
  <pre><code>&lt;import resource="classpath:/app-context.xml"/&gt;
  </code></pre>
  
  <p>to </p>
  
  <pre><code>&lt;import resource="classpath*:**/app-context.xml"/&gt;
  </code></pre>
  
  <p>now it detects the <code>app-context.xml</code> but fails to autowire <code>ThreadService</code>.</p>
  
  <pre><code>   org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myHandler': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.x.y.service.ThreadService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}
          at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:308)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
          at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
          at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
          at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
          at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
          at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
          at message.objects.Application.main(Application.java:17)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:497)
          at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
          at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>I am not sure why spring-boot is not able to detect the beans.</p>
  
  <p>I have tried the following :</p>
  
  <ol>
  <li>Tried adding <code>@ImportResource("classpath:/beans.xml")</code> on <code>my controller</code> as well as <code>Application</code> class.</li>
  <li><p>I tried using <code>repackage</code></p>
  
  <pre><code>   &lt;plugin&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
          &lt;version&gt;1.2.5.RELEASE&lt;/version&gt;
          &lt;executions&gt;
              &lt;execution&gt;
                  &lt;goals&gt;
                      &lt;goal&gt;repackage&lt;/goal&gt;
                  &lt;/goals&gt;
              &lt;/execution&gt;
          &lt;/executions&gt;
      &lt;/plugin&gt;
  </code></pre></li>
  </ol>