title: Access the service layer from the controller
body: <p>I am using a REST web service that queries data from Apache Solr. I'm using Spring boot + data with Solr repositories.
  I do not know how to interconnect as service, repository, and controller layers.</p>
  
  <p><a href="https://i.stack.imgur.com/PmEJX.png" rel="nofollow noreferrer">I have the following structure</a></p>
  
  <p><strong>Controller</strong>:</p>
  
  <pre><code>@RestController
  public class ImageSearchController {
  
      private final Logger log = LoggerFactory.getLogger( this.getClass( ) ); 
      @Resource ImageService imageService;
  ....
  }
  </code></pre>
  
  <p><strong>Main to SpringBootApplication</strong>: </p>
  
  <pre><code>@SpringBootApplication
  public class Application extends SpringBootServletInitializer{
  
      public static void main( String[ ] args ) {
          SpringApplication.run( Application.class , args );
      }
  
  }
  </code></pre>
  
  <p><strong>Service</strong>:</p>
  
  <pre><code>public interface ImageService {
  
      List&lt; Image &gt; searchTerm( String searchTerm );
      List&lt; Image &gt; search(String imgSrc , String imgTitle);
      List&lt; Image &gt; searchByImgSrc( String searchTerm );
      List&lt; Image &gt; findAll( );   
  }
  </code></pre>
  
  <p><strong>Service Impl</strong>:</p>
  
  <pre><code>@Service
  public class ImageServiceImpl implements ImageService {
  
      @Resource
      private ImageRepository repository;
  
  
      @Override
      public List&lt; Image &gt; search( String imgSrc , String imgTitle ) {
          return repository.findByImgSrcContainsOrImgTitleContains( imgSrc , imgTitle );
      }
  ....
  }
  </code></pre>
  
  <p><strong>Repository (Spring Data)</strong>:</p>
  
  <pre><code>public interface ImageRepository extends SolrCrudRepository&lt; Image , String &gt; {
  
      public List&lt; Image &gt; findAll( );
  
  ...
  }
  </code></pre>
  
  <p><strong>Pom.xml</strong>:</p>
  
  <pre><code>    &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;!-- https://mvnrepository.com/artifact/org.apache.solr/solr-solrj --&gt;
           &lt;dependency&gt;
              &lt;groupId&gt;org.apache.solr&lt;/groupId&gt;
              &lt;artifactId&gt;solr-solrj&lt;/artifactId&gt;
              &lt;version&gt;5.1.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-solr --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
              &lt;artifactId&gt;spring-data-solr&lt;/artifactId&gt;
              &lt;version&gt;2.1.1.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;   
      &lt;/dependencies&gt;
  ...
  
      &lt;repositories&gt;
          &lt;repository&gt;
              &lt;id&gt;spring-releases&lt;/id&gt;
              &lt;url&gt;https://repo.spring.io/libs-release&lt;/url&gt;
          &lt;/repository&gt;
          &lt;repository&gt;
              &lt;id&gt;spring-milestone&lt;/id&gt;
              &lt;name&gt;Spring Milestone Maven Repository&lt;/name&gt;
              &lt;url&gt;http://repo.springsource.org/libs-milestone&lt;/url&gt;
          &lt;/repository&gt;
      &lt;/repositories&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/fsoZi.png" rel="nofollow noreferrer">Logs of application</a></p>
  
  <p>How to create the bean and access the controller in the service layer?
  How to configure solr client with rest web service ?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I upgraded the spring boot version from 1.4.3 to 1.5.1 and it worked. Honestly, I do not understand why.
  Now I get another error, when accessing solr, the spring data duplicates the name of the core in solr. Any idea ?</p>
  
  <p>Thanks</p>