title: How should I use JpaRepository.findOne() with SpringBoot?
body: <p>I just started learning Spring Boot by reading the book <em>Spring Boot in Action</em> and I am <strong>learning the examples</strong> of this book, trying to run them myself but I have a problem using <code>JpaRepository.findOne()</code>.</p>
  
  <p>I've gone allover the Chapter to find my possible mismatches. However, it just DO NOT work. </p>
  
  <p>The project is supposed to be a simple Reading List. </p>
  
  <p>Here is the code :</p>
  
  <p>The Reader @Entity:</p>
  
  <pre><code>package com.lixin.readinglist;
  
  import org.springframework.data.annotation.Id;
  import org.springframework.security.core.GrantedAuthority;
  import org.springframework.security.core.authority.SimpleGrantedAuthority;
  import org.springframework.security.core.userdetails.UserDetails;
  
  import javax.persistence.Entity;
  import java.util.Collection;
  import java.util.Collections;
  
  /**
   * @author lixin
   */
  @Entity
  public class Reader implements UserDetails {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      private String username;
      private String fullname;
      private String password;
  
      @Override
      public String getUsername() {
          return username;
      }
  
      public void setUsername(String username) {
          this.username = username;
      }
  
      public String getFullname() {
          return fullname;
      }
  
      public void setFullname(String fullname) {
          this.fullname = fullname;
      }
  
      @Override
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      @Override
      public Collection&lt;? extends GrantedAuthority&gt; getAuthorities() {
          return Collections.singletonList(new SimpleGrantedAuthority("READER"));
      }
  
      @Override
      public boolean isAccountNonExpired() {
          return true;
      }
  
      @Override
      public boolean isAccountNonLocked() {
          return true;
      }
  
      @Override
      public boolean isCredentialsNonExpired() {
          return true;
      }
  
      @Override
      public boolean isEnabled() {
          return true;
      }
  }
  </code></pre>
  
  <p>The Jpa interface:</p>
  
  <pre><code>package com.lixin.readinglist;
  
  import org.springframework.data.jpa.repository.JpaRepository;
  
  /**
   * @author lixin
   */
  public interface ReaderRepository extends JpaRepository&lt;Reader, String&gt; {
  }
  </code></pre>
  
  <p>The SecurityConfig:</p>
  
  <pre><code>package com.lixin.readinglist;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  import org.springframework.security.core.userdetails.UserDetailsService;
  
  /**
   * @author lixin
   */
  @Configuration
  @EnableWebSecurity
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
      private final ReaderRepository readerRepository;
  
      @Autowired
      public SecurityConfig(ReaderRepository readerRepository) {
          this.readerRepository = readerRepository;
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http
                  .authorizeRequests()
                  .antMatchers("/").access("hasRole('READER')")
                  .antMatchers("/**").permitAll()
                  .and()
                  .formLogin()
                  .loginPage("/login")
                  .failureUrl("/login?error=true");
      }
  
      @Override
      protected void configure(AuthenticationManagerBuilder auth) throws Exception {
          auth
                  .userDetailsService((UserDetailsService) username -&gt; readerRepository.findOne(username));
      }
  }
  </code></pre>
  
  <p>And I kept getting this ERROR:</p>
  
  <pre><code>Error:(40, 86) java: method findOne in interface org.springframework.data.repository.query.QueryByExampleExecutor&lt;T&gt; cannot be applied to given types;
    required: org.springframework.data.domain.Example&lt;S&gt;
    found: java.lang.String
    reason: cannot infer type-variable(s) S
      (argument mismatch; java.lang.String cannot be converted to org.springframework.data.domain.Example&lt;S&gt;)
  </code></pre>