title: Spring Boot Application can not inject Bean from another module
body: <p>I have the following 3 modules in my spring-boot application:</p>
  <ul>
  <li>web (Entry point / Main Application class annotated with <code>@SpringBootApplication</code></li>
  <li>persistence</li>
  <li>service</li>
  </ul>
  <p>I'm now trying to inject a service in the <code>web</code> module which comes from the <code>service</code>. In the service I'm injecting the repository which comes from the <code>persistence</code> module. When I start the application the following error shows up:</p>
  <pre><code>***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Parameter 0 of constructor in com.project.service.images.ImageService required a bean of type 'com.project.persistence.repositories.ImageRepository' that could not be found.
  
  
  Action:
  
  Consider defining a bean of type 'com.project.persistence.repositories.ImageRepository' in your configuration.
  </code></pre>
  <p><code>ImageService</code> class:</p>
  <pre class="lang-java prettyprint-override"><code>package com.project.service.images;
  
  import com.project.common.entities.Image;
  import com.project.persistence.repositories.ImageRepository;
  import com.project.service.AbstractService;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Component;
  
  import javax.persistence.EntityNotFoundException;
  import java.util.Date;
  import java.util.List;
  
  @Component
  public class ImageService extends AbstractService {
  
      private final ImageRepository imageRepository;
  
      @Autowired
      public ImageService(ImageRepository imageRepository) {
          this.imageRepository = imageRepository;
      }
  
      public Image getImage(Long id) {
          return imageRepository.findById(id).orElseThrow(EntityNotFoundException::new);
      }
  
      public List&lt;Image&gt; getAll() {
          return imageRepository.findAll();
      }
  
      public List&lt;Image&gt; getAll(Date from) {
          return imageRepository.findByDateRange(from, null);
      }
  
      public List&lt;Image&gt; getAll(Date from, Date to) {
          return imageRepository.findByDateRange(from, to);
      }
  
      public List&lt;Image&gt; getAllForDay(Date day) {
          return imageRepository.findAll();
      }
  }
  </code></pre>
  <p><code>ImageRepository</code> class:</p>
  <pre class="lang-java prettyprint-override"><code>package com.project.persistence.repositories;
  
  import com.project.common.entities.Image;
  import org.springframework.data.jpa.repository.JpaRepository;
  import org.springframework.data.jpa.repository.Query;
  import org.springframework.data.repository.query.Param;
  import org.springframework.stereotype.Repository;
  
  import java.util.Date;
  import java.util.List;
  
  @Repository
  public interface ImageRepository extends JpaRepository&lt;Image, Long&gt; {
  
      @Query(&quot;SELECT i FROM Image i WHERE i.created &gt; :from AND i.created &lt; :to&quot;)
      public List&lt;Image&gt; findByDateRange(@Param(&quot;from&quot;) Date from, @Param(&quot;to&quot;) Date to);
  }
  </code></pre>
  <p>And that's how I inject the service into my class in the <code>web</code> module:</p>
  <pre class="lang-java prettyprint-override"><code>@Autowired
  private ImageService imageService;
  </code></pre>
  <p>So on I was searching throught the internet and saw some people with similar problems. Then I got the tip that I should add the <code>scanBasePackages</code> to the <code>SpringBootApplication</code> annotation at my application class. So I did this:</p>
  <pre class="lang-java prettyprint-override"><code>package com.project.web;
  
  @SpringBootApplication(scanBasePackages = &quot;com.project.service&quot;)
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  <p>But it's still not working. If I add the specific package for scanning to the annotation <code>com.project.service.images</code> the injection of the <code>ImageService</code> works but then it can't find the <code>ImageRepository</code> in it.</p>
  <p>What am I doing wrong?</p>
  <p>I know that so many modules doesn't make sense for such a small application but I have to because it's for my apprenticeship and we need to make multiple modules.</p>