title: BeanCreationException : Invocation of init method failed
body: <p>I am trying to implement LDAP configuration for my Spring Project but LDAP Repository is not getting initialized. </p>
  
  <p>Error Trace is - </p>
  
  <pre><code>xx:xx:xx.116 [localhost-startStop-1] WARN  o.s.w.c.s.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepo': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.ldap.repository.support.LdapRepositoryFactory$LdapQueryLookupStrategy.resolveQuery(Ljava/lang/reflect/Method;Lorg/springframework/data/repository/core/RepositoryMetadata;Lorg/springframework/data/projection/ProjectionFactory;Lorg/springframework/data/repository/core/NamedQueries;)Lorg/springframework/data/repository/query/RepositoryQuery;
  xx:xx:xx.124 [localhost-startStop-1] ERROR o.s.web.context.ContextLoader - Context initialization failed
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepo': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.ldap.repository.support.LdapRepositoryFactory$LdapQueryLookupStrategy.resolveQuery(Ljava/lang/reflect/Method;Lorg/springframework/data/repository/core/RepositoryMetadata;Lorg/springframework/data/projection/ProjectionFactory;Lorg/springframework/data/repository/core/NamedQueries;)Lorg/springframework/data/repository/query/RepositoryQuery;
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) [spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068) [catalina.jar:7.0.68]
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584) [catalina.jar:7.0.68]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) [catalina.jar:7.0.68]
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572) [catalina.jar:7.0.68]
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562) [catalina.jar:7.0.68]
      at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_73]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_73]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_73]
      at java.lang.Thread.run(Thread.java:745) [na:1.8.0_73]
  Caused by: java.lang.AbstractMethodError: org.springframework.ldap.repository.support.LdapRepositoryFactory$LdapQueryLookupStrategy.resolveQuery(Ljava/lang/reflect/Method;Lorg/springframework/data/repository/core/RepositoryMetadata;Lorg/springframework/data/projection/ProjectionFactory;Lorg/springframework/data/repository/core/NamedQueries;)Lorg/springframework/data/repository/query/RepositoryQuery;
      at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.&lt;init&gt;(RepositoryFactorySupport.java:435) ~[spring-data-commons-1.12.1.RELEASE.jar:na]
      at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:220) ~[spring-data-commons-1.12.1.RELEASE.jar:na]
      at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:266) ~[spring-data-commons-1.12.1.RELEASE.jar:na]
      at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:252) ~[spring-data-commons-1.12.1.RELEASE.jar:na]
      at org.springframework.ldap.repository.support.LdapRepositoryFactoryBean.afterPropertiesSet(LdapRepositoryFactoryBean.java:47) ~[spring-ldap-core-2.0.4.RELEASE.jar:2.0.4.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      ... 21 common frames omitted
  </code></pre>
  
  <p>UserRepo.java</p>
  
  <pre><code>package domain;
  
  import org.springframework.ldap.repository.LdapRepository;
  import java.util.List;
  
  
  public interface UserRepo extends LdapRepository&lt;User&gt; {
      User findByEmployeeNumber(int employeeNumber);
      List&lt;User&gt; findByFullNameContains(String name);
  }
  </code></pre>
  
  <p>applicationContext.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:ldap="http://www.springframework.org/schema/ldap"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd"&gt;
  
      &lt;context:property-placeholder location="classpath:/ldap.properties" system-properties-mode="OVERRIDE" /&gt;
      &lt;context:annotation-config /&gt;
  
      &lt;ldap:context-source id="contextSource"
                           password="${sample.ldap.password}"
                           url="${sample.ldap.url}"
                           username="${sample.ldap.userDn}"
                           base="${sample.ldap.base}" /&gt;
  
      &lt;ldap:ldap-template id="ldapTemplate" context-source-ref="contextSource"/&gt;
  
      &lt;!--
          This will scan the org.springframework.ldap.samples.useradmin.domain package for interfaces
          extending CrudRepository (in our case, LdapRepository), automatically creating repository
          beans based on these interfaces.
      --&gt;
      &lt;ldap:repositories base-package="domain" /&gt;
  
  
      &lt;bean class="service.UserService"&gt;
          &lt;property name="directoryType" value="${sample.ldap.directory.type}" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- Required to make sure BaseLdapName is populated in UserService --&gt;
      &lt;bean class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor" /&gt;
  
      &lt;beans profile="default"&gt;
          &lt;!-- Populates the LDAP server with initial data --&gt;
          &lt;bean class="org.springframework.ldap.test.LdifPopulator" depends-on="embeddedLdapServer"&gt;
              &lt;property name="contextSource" ref="contextSource" /&gt;
              &lt;property name="resource" value="classpath:/setup_data.ldif" /&gt;
              &lt;property name="base" value="${sample.ldap.base}" /&gt;
              &lt;property name="clean" value="${sample.ldap.clean}" /&gt;
              &lt;property name="defaultBase" value="dc=example,dc=com" /&gt;
          &lt;/bean&gt;
  
          &lt;!--
              This is for test and demo purposes only - EmbeddedLdapServerFactoryBean launches an in-process
              LDAP server.
          --&gt;
          &lt;bean id="embeddedLdapServer" class="org.springframework.ldap.test.EmbeddedLdapServerFactoryBean"&gt;
              &lt;property name="partitionName" value="example"/&gt;
              &lt;property name="partitionSuffix" value="${sample.ldap.base}" /&gt;
              &lt;property name="port" value="18880" /&gt;
          &lt;/bean&gt;
      &lt;/beans&gt;
  
      &lt;beans profile="no-apacheds"&gt;
          &lt;!-- Populates the LDAP server with initial data --&gt;
          &lt;bean class="org.springframework.ldap.test.LdifPopulator"&gt;
              &lt;property name="contextSource" ref="contextSource" /&gt;
              &lt;property name="resource" value="classpath:/setup_data.ldif" /&gt;
              &lt;property name="base" value="${sample.ldap.base}" /&gt;
              &lt;property name="clean" value="${sample.ldap.clean}" /&gt;
              &lt;property name="defaultBase" value="dc=example,dc=com" /&gt;
          &lt;/bean&gt;
      &lt;/beans&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>UserService.java</p>
  
  <pre><code>package service;
  
  import java.util.List;
  import java.util.Set;
  
  import javax.naming.Name;
  import javax.naming.ldap.LdapName;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.ldap.core.support.BaseLdapNameAware;
  import org.springframework.ldap.support.LdapNameBuilder;
  import org.springframework.ldap.support.LdapUtils;
  
  import com.google.common.base.Function;
  import com.google.common.collect.Iterables;
  import com.google.common.collect.Sets;
  
  import domain.DirectoryType;
  import domain.User;
  import domain.UserRepo;
  
  /**
   * 
   */
  public class UserService implements BaseLdapNameAware {
  
      private final UserRepo userRepo;
      private LdapName baseLdapPath;
      private DirectoryType directoryType;
  
      @Autowired
      public UserService(UserRepo userRepo) {
          this.userRepo = userRepo;
          //this.groupRepo = groupRepo;
      }
  
  
      public void setDirectoryType(DirectoryType directoryType) {
          this.directoryType = directoryType;
      }
  
      public void setBaseLdapPath(LdapName baseLdapPath) {
          this.baseLdapPath = baseLdapPath;
      }
  
      public Iterable&lt;User&gt; findAll() {
          return userRepo.findAll();
      }
  
      public User findUser(String userId) {
          return userRepo.findOne(LdapUtils.newLdapName(userId));
      }
  
  
  
      public LdapName toAbsoluteDn(Name relativeName) {
          return LdapNameBuilder.newInstance(baseLdapPath)
                  .add(relativeName)
                  .build();
      }
  
      /**
       * This method expects absolute DNs of group members. In order to find the actual users
       * the DNs need to have the base LDAP path removed.
       *
       * @param absoluteIds
       * @return
       */
      public Set&lt;User&gt; findAllMembers(Iterable&lt;Name&gt; absoluteIds) {
          return Sets.newLinkedHashSet(userRepo.findAll(toRelativeIds(absoluteIds)));
      }
  
      public Iterable&lt;Name&gt; toRelativeIds(Iterable&lt;Name&gt; absoluteIds) {
          return Iterables.transform(absoluteIds, new Function&lt;Name, Name&gt;() {
              public Name apply(Name input) {
                  return LdapUtils.removeFirst(input, baseLdapPath);
              }
          });
      }
  
  
      public List&lt;User&gt; searchByNameName(String lastName) {
          return userRepo.findByFullNameContains(lastName);
      }
  }
  </code></pre>
  
  <p>Following are dependencies-</p>
  
  <p><a href="https://i.stack.imgur.com/iByrv.png" rel="noreferrer"><img src="https://i.stack.imgur.com/iByrv.png" alt="enter image description here"></a></p>
  
  <p>I am not able to resolve this error. LDAP repositories base package is mentioned in applicationContext.xml but still exption follows.
  Please let me know for correct implimentation.</p>
  
  <p>Edit - : Dependency tree</p>
  
  <p><a href="https://i.stack.imgur.com/AZYJn.png" rel="noreferrer"><img src="https://i.stack.imgur.com/AZYJn.png" alt="enter image description here"></a></p>