title: Spring Boot: autowire beans from library project
body: <p>I'm struggling to autowire beans from my custom library, imported with gradle.
  after reading couple of similar topics I am still unable to find solution.</p>
  <p>I have a Spring Boot project that depends on another project (my custom library with Components, Repositories etc...). This library is a Spring non-runnable jar, that consists primarily of domain Entities and Repositories. It doesn't have runnable Application.class and any properties...</p>
  <p>When I start the application I can see that My 'CustomUserService' bean (from the library) is trying to be initialized, but the bean autowired in it failed to load (interface UserRepository)...</p>
  <p>Error:</p>
  <blockquote>
  <p>Parameter 0 of constructor in
  com.myProject.customLibrary.configuration.CustomUserDetailsService
  required a bean of type
  'com.myProject.customLibrary.configuration.UserRepository' that could not
  be found.</p>
  </blockquote>
  <p>I've even tried to set 'Order', to load it explicitly (with <code>scanBasePackageClasses</code>), scan with packages and marker classes, add additional <code>EnableJPARepository</code> annotation but nothing works...</p>
  <p>Code example (packages names were changed for simplicity)</p>
  <pre class="lang-java prettyprint-override"><code>package runnableProject.application;
  
  import runnableProject.application.configuration.ServerConfigurationReference.class
  import com.myProject.customLibrary.SharedReference.class
  
  //@SpringBootApplication(scanBasePackages = {&quot;com.myProject.customLibrary&quot;, &quot;runnableProject.configuration&quot;}) 
  //@EnableJpaRepositories(&quot;com.myProject.customLibrary&quot;)  
  
  @SpringBootApplication(scanBasePackageClasses = {SharedReference.class, ServerConfigurationReference.class})   
  public class MyApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(MyApplication.class, args);
      }
  
  }
  </code></pre>
  <p>Classes from the library:</p>
  <pre class="lang-java prettyprint-override"><code>package com.myProject.customLibrary.configuration;
  
  import com.myProject.customLibrary.configuration.UserRepository.class;
  
  @Service
  public class CustomUserDetailsService implements UserDetailsService {
      private UserRepository userRepository;    
  
      @Autowired
      public CustomUserDetailsService(UserRepository userRepository) {
          this.userRepository = userRepository;       
      }
  ...
  
  package myProject.customLibrary.configuration;
  
  @Repository
  public interface UserRepository extends CustomRepository&lt;User&gt; {
      User findByLoginAndStatus(String var1, Status var2);
  
      ...
  }
  </code></pre>