web-dev-qa-db-fra.com

BeanCreationException: échec de l'appel de la méthode init

J'essaie d'implémenter la configuration LDAP pour mon projet Spring, mais le référentiel LDAP n'est pas initialisé.

La trace d'erreur est -

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.<init>(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

UserRepo.Java

package domain;

import org.springframework.ldap.repository.LdapRepository;
import Java.util.List;


public interface UserRepo extends LdapRepository<User> {
    User findByEmployeeNumber(int employeeNumber);
    List<User> findByFullNameContains(String name);
}

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>

<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">

    <context:property-placeholder location="classpath:/ldap.properties" system-properties-mode="OVERRIDE" />
    <context:annotation-config />

    <ldap:context-source id="contextSource"
                         password="${sample.ldap.password}"
                         url="${sample.ldap.url}"
                         username="${sample.ldap.userDn}"
                         base="${sample.ldap.base}" />

    <ldap:ldap-template id="ldapTemplate" context-source-ref="contextSource"/>

    <!--
        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.
    -->
    <ldap:repositories base-package="domain" />


    <bean class="service.UserService">
        <property name="directoryType" value="${sample.ldap.directory.type}" />
    </bean>

    <!-- Required to make sure BaseLdapName is populated in UserService -->
    <bean class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor" />

    <beans profile="default">
        <!-- Populates the LDAP server with initial data -->
        <bean class="org.springframework.ldap.test.LdifPopulator" depends-on="embeddedLdapServer">
            <property name="contextSource" ref="contextSource" />
            <property name="resource" value="classpath:/setup_data.ldif" />
            <property name="base" value="${sample.ldap.base}" />
            <property name="clean" value="${sample.ldap.clean}" />
            <property name="defaultBase" value="dc=example,dc=com" />
        </bean>

        <!--
            This is for test and demo purposes only - EmbeddedLdapServerFactoryBean launches an in-process
            LDAP server.
        -->
        <bean id="embeddedLdapServer" class="org.springframework.ldap.test.EmbeddedLdapServerFactoryBean">
            <property name="partitionName" value="example"/>
            <property name="partitionSuffix" value="${sample.ldap.base}" />
            <property name="port" value="18880" />
        </bean>
    </beans>

    <beans profile="no-apacheds">
        <!-- Populates the LDAP server with initial data -->
        <bean class="org.springframework.ldap.test.LdifPopulator">
            <property name="contextSource" ref="contextSource" />
            <property name="resource" value="classpath:/setup_data.ldif" />
            <property name="base" value="${sample.ldap.base}" />
            <property name="clean" value="${sample.ldap.clean}" />
            <property name="defaultBase" value="dc=example,dc=com" />
        </bean>
    </beans>
</beans>

UserService.Java

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<User> 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<User> findAllMembers(Iterable<Name> absoluteIds) {
        return Sets.newLinkedHashSet(userRepo.findAll(toRelativeIds(absoluteIds)));
    }

    public Iterable<Name> toRelativeIds(Iterable<Name> absoluteIds) {
        return Iterables.transform(absoluteIds, new Function<Name, Name>() {
            public Name apply(Name input) {
                return LdapUtils.removeFirst(input, baseLdapPath);
            }
        });
    }


    public List<User> searchByNameName(String lastName) {
        return userRepo.findByFullNameContains(lastName);
    }
}

Voici les dépendances-

enter image description here

Je ne parviens pas à résoudre cette erreur. Le package de base des référentiels LDAP est mentionné dans applicationContext.xml mais une exception suit toujours. Veuillez me le faire savoir pour une implantation correcte.

Édition -: Arbre de dépendance

enter image description here

5
NewBee

Depuis JavaDoc pour AbstractMethodError:

Lancé lorsqu'une application tente d'appeler une méthode abstraite. Normalement, cette erreur est détectée par le compilateur; cette erreur ne peut se produire au moment de l'exécution que si la définition d'une classe a changé de manière incompétente depuis la dernière compilation de la méthode en cours d'exécution.

Cela signifie que la version déployée de Spring est différente de celle que vous avez utilisée pour compiler le code.

Assurez-vous que les bibliothèques déployées sont de la même version que celles de votre IDE

1
Jim Garrison