title: How to create the bean of FindByIndexNameSessionRepository
body: <p>I am trying to create the Bean of FindByIndexNameSessionRepository. I need to get all user sessions using it but I am getting the bean error even I already defined it. I am using the Spring Boot Starter 1.5.7</p>
  
  <blockquote>
    <p><strong>Error:</strong> Field sessionRepository required a bean of type 'org.springframework.session.FindByIndexNameSessionRepository' that could not be found.</p>
    
    <p>Consider defining a bean of type
    'org.springframework.session.FindByIndexNameSessionRepository' in your
    configuration.</p>
  </blockquote>
  
  <p>I am trying to create bean and using it in my configuration, something like that:</p>
  
  <pre><code>import com.x.security.SpringSessionBackedSessionRegistry;
  @Bean
  SpringSessionBackedSessionRegistry sessionRegistry() {
      return new SpringSessionBackedSessionRegistry&lt;ExpiringSession&gt;(
              this.sessionRepository);
  }
  @Autowired
  private FindByIndexNameSessionRepository&lt;ExpiringSession&gt; sessionRepository;
  </code></pre>
  
  <p>My configuration is below</p>
  
  <pre><code>http&lt;...&gt;
     .maximumSessions(2)
     .sessionRegistry(sessionRegistry())
      .maxSessionsPreventsLogin(false)
      .&lt;other settings&gt;           
  </code></pre>
  
  <p>My SpringSessionBackedSessionRegistry class is as follow:</p>
  
  <pre><code>public class SpringSessionBackedSessionRegistry&lt;S extends ExpiringSession&gt;
      implements SessionRegistry {
    private final FindByIndexNameSessionRepository&lt;S&gt; sessionRepository;
  
  
  public SpringSessionBackedSessionRegistry(
          FindByIndexNameSessionRepository&lt;S&gt; sessionRepository) {
      Assert.notNull(sessionRepository, "sessionRepository cannot be null");
      this.sessionRepository = sessionRepository;
       }
       @Override
  public List&lt;Object&gt; getAllPrincipals() {
      throw new UnsupportedOperationException("SpringSessionBackedSessionRegistry does "
              + "not support retrieving all principals, since Spring Session provides "
              + "no way to obtain that information");
  }
  @Override
  public List&lt;SessionInformation&gt; getAllSessions(Object principal,
          boolean includeExpiredSessions) {
      Collection&lt;S&gt; sessions = this.sessionRepository.findByIndexNameAndIndexValue(
              FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME,
              name(principal)).values();
      List&lt;SessionInformation&gt; infos = new ArrayList&lt;&gt;();
      for (S session : sessions) {
          if (includeExpiredSessions || !Boolean.TRUE.equals(session
                  .getAttribute(SpringSessionBackedSessionInformation.EXPIRED_ATTR))) {
              infos.add(new SpringSessionBackedSessionInformation&lt;S&gt;(session,
                      this.sessionRepository));
          }
      }
      return infos;
  }
  
  @Override
  public SessionInformation getSessionInformation(String sessionId) {
      S session = this.sessionRepository.getSession(sessionId);
      if (session != null) {
          return new SpringSessionBackedSessionInformation&lt;S&gt;(session,
                  this.sessionRepository);
      }
      return null;
  }
  
  /*
   * This is a no-op, as we don't administer sessions ourselves.
   */
   @Override
  public void refreshLastRequest(String sessionId) {
  }
  
  /*
   * This is a no-op, as we don't administer sessions ourselves.
   */
   @Override
  public void registerNewSession(String sessionId, Object principal) {
  }
  
  /*
   * This is a no-op, as we don't administer sessions ourselves.
   */
   @Override
  public void removeSessionInformation(String sessionId) {
  }
  
  /**
   * Derives a String name for the given principal.
   *
   * @param principal as provided by Spring Security
   * @return name of the principal, or its {@code toString()} representation if no name
   * could be derived
   */
  
  protected String name(Object principal) {
      if (principal instanceof UserDetails) {
          return ((UserDetails) principal).getUsername();
      }
      if (principal instanceof Principal) {
          return ((Principal) principal).getName();
      }
      return principal.toString();
  }
  
  }
  </code></pre>
  
  <p>My pom snippet is as follows</p>
  
  <pre><code>&lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.5.7.RELEASE&lt;/version&gt;
  &lt;/parent&gt;
  
  &lt;properties&gt;
      &lt;java.version&gt;1.8&lt;/java.version&gt;
  &lt;/properties&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-redis&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.session&lt;/groupId&gt;
          &lt;artifactId&gt;spring-session&lt;/artifactId&gt;
      &lt;/dependency&gt;   
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>Any help is much appreciated.</p>