需要你的帮助。将 java 对象映射为包含属性的用户时,我得到 null ref。
@Entry(objectClasses = {"person","top"} )
public final class Users{
@Id
private Name dn;
@Attribute(name="givenName")
private String firstName;
@Attribute(name="uid")
private String uid;
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
@Attribute(name="sn")
private String lastName;
@Attribute(name="cn")
private String fullName;
并将其调用到 main 方法中:
public class Test {
private static final SearchControls searchControls =
new SearchControls(SearchControls.SUBTREE_SCOPE, 0, 10000,
null, true, false);
private static final DistinguishedName baseDn = new DistinguishedName("ou=sa,o=data");
private static void print(List<Users> personList) {
for (Users person : personList) {
System.out.println(person);
}
}
public static void main(String[] argv) {
ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "LdapContextSource.xml" });
OdmManager odmManager = (OdmManager)context.getBean("odmManager");
Users user=new Users();
List<Users> searchResults = odmManager.findAll(Users.class,baseDn, searchControls);
System.out.println(searchResults.get(0));
}
}
这是我的springcontext文件;
<?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:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
<bean id="fromStringConverter" class="org.springframework.ldap.odm.typeconversion.impl.converters.FromStringConverter" />
<bean id="toStringConverter" class="org.springframework.ldap.odm.typeconversion.impl.converters.ToStringConverter" />
<bean id="converterManager" class="org.springframework.ldap.odm.typeconversion.impl.ConverterManagerFactoryBean">
<property name="converterConfig">
<set>
<bean class="org.springframework.ldap.odm.typeconversion.impl.ConverterManagerFactoryBean$ConverterConfig">
<property name="fromClasses">
<set>
<value>java.lang.String</value>
</set>
</property>
<property name="toClasses">
<set>
<value>java.lang.Byte</value>
<value>java.lang.Short</value>
<value>java.lang.Integer</value>
<value>java.lang.Long</value>
<value>java.lang.Float</value>
<value>java.lang.Double</value>
<value>java.lang.Boolean</value>
</set>
</property>
<property name="converter" ref="fromStringConverter" />
</bean>
<bean class="org.springframework.ldap.odm.typeconversion.impl.ConverterManagerFactoryBean$ConverterConfig">
<property name="fromClasses">
<set>
<value>java.lang.Byte</value>
<value>java.lang.Short</value>
<value>java.lang.Integer</value>
<value>java.lang.Long</value>
<value>java.lang.Float</value>
<value>java.lang.Double</value>
<value>java.lang.Boolean</value>
</set>
</property>
<property name="toClasses">
<set>
<value>java.lang.String</value>
</set>
</property>
<property name="converter" ref="toStringConverter" />
</bean>
</set>
</property>
</bean>
<bean id="contextSourceTarget" class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="ldap://172.16.9.27" />
<!-- <property name="base" value="o=data" /> -->
<property name="userDn" value="cn=adminua,ou=sa,o=data" />
<property name="password" value="12345" />
<property name="pooled" value="false" />
</bean>
<bean id="dirContextValidator" class="org.springframework.ldap.pool.validation.DefaultDirContextValidator">
<property name="base" value="" />
<property name="filter" value="objectclass=person" />
<property name="searchControls.searchScope">
<util:constant static-field="javax.naming.directory.SearchControls.OBJECT_SCOPE" />
</property>
</bean>
<bean id="contextSource" class="org.springframework.ldap.pool.factory.PoolingContextSource">
<property name="contextSource" ref="contextSourceTarget" />
<property name="dirContextValidator" ref="dirContextValidator" />
<property name="maxActive" value="10" />
<property name="maxTotal" value="10" />
<property name="maxIdle" value="5" />
<property name="minIdle" value="1" />
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<property name="testOnBorrow" value="true" />
<property name="testWhileIdle" value="true" />
</bean>
<bean id="odmManager" class="org.springframework.ldap.odm.core.impl.OdmManagerImplFactoryBean">
<property name="converterManager" ref="converterManager" />
<property name="contextSource" ref="contextSource" />
<property name="managedClasses">
<set>
<value>test.idm.core.entity.Users</value>
</set>
</property>
</bean>
</beans>
请告诉我错误在哪里。