Call repository and service from controller layer with Spring
<p>I use Spring Boot and Spring Data.</p>

<p>I have no problem in my mind to separate Repository Layer and Service Layer</p>

<p>So I have my UserRepository with CRUD method and some Spring Data method</p>

<ul>
<li>findAll</li>
<li>findByUsername</li>
</ul>

<p>I also have UserService with business method.</p>

<ul>
<li>checkPassword(String login,String password)</li>
<li>businessMethodAction(String username)</li>
</ul>

<p>Here is my question:</p>

<p>In my controller I have to call method from UserService and sometime from UserRepository. For the moment, I inject both in my controller, and I call service or repository</p>

<pre><code>@Inject
UserService userService;

@Inject
UserRepository userRepository;

@RequestMapping("{username}")
private void myMethod(@PathVariable String username){
    return userRepository.findOne(username);
}

@RequestMapping("{username}/doBusineesAction")
private void myMethod(@PathVariable String username){
    return userService.doLogicalThin(username);
}
</code></pre>

<p>I'm just asking because I confused to inject both and to call one or the other in the same class</p>

<p>On another side, this would mean to duplicate method in service layer like this</p>

<pre><code>public User findOne(String username){
 return userRepository.findOne(username);
}
</code></pre>

<p>What's your opinion?</p>