集成spring-ldap


1.pom文件增加

  <dependency>
            <groupId>org.springframework.ldap</groupId>
            <artifactId>spring-ldap-core</artifactId>
            <version>2.3.2.RELEASE</version>
        </dependency>

2.spring配置文件增加

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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/ldap
http://www.springframework.org/schema/ldap/spring-ldap.xsd"
>
    <bean id="contextSource"    
        class="org.springframework.ldap.core.support.LdapContextSource">    
        <property name="url" value="ldap://192.168.80.123:389" />    
        <property name="base" value="dc=kpzc,dc=local" />    
        <property name="userDn" value="admin@kpzc.local" />    
        <property name="password" value="kpzc" />  
    </bean>  
      
    <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">    
        <constructor-arg ref="contextSource" />  
    </bean>

url 賬號 密碼 我是固定寫死的 也可配置在properties文件中

 

3.啟動項目會出現


17:02:24.853 [main] DEBUG o.s.l.c.s.AbstractContextSource - AuthenticationSource not set - using default implementation
17:02:24.854 [main] DEBUG o.s.l.c.s.AbstractContextSource - Not using LDAP pooling
17:02:24.857 [main] DEBUG o.s.l.c.s.AbstractContextSource - Trying provider Urls: ldap://192.168.80.123:389/dc=kpzc,dc=local

即可使用Autowired注解了

@Autowired
private LdapTemplate ldapTemplate;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM