This is a follow-up to the question: spring ldap 2.0.1 replacing deprecated OdmManager
Here is a snippet of a JUnit test:
@Autowired
private LdapTemplate ldapTemplate;
@Autowired
private ObjectDirectoryMapper objectDirectoryMapper;
@Before
public void setUp() {
ldapTemplate.setObjectDirectoryMapper(objectDirectoryMapper);
}
I would like to avoid programmatically setting the objectDirectoryMapper as shown in setUp(), but I'm unsure from looking at the schema of the <ldap:ldap-template .../> tag whether there's a way to inject the objectDirectoryMapper
property in the XML instead of programmatically. I may be missing something obvious...
Here's the relevant XML. As you can see I'm trying to wire a converter which is the goal (update: actually the main goal is inject my custom converter to be used by the LdapRepository<User>
:
<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:/test/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" />
<ldap:repositories base-package="my.domain" />
...
<bean id="conversionService"
class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<list>
<bean class="my.domain.StringToRealmConverter" />
<bean class="my.domain.RealmToStringConverter"/>
</list>
</property>
</bean>
...
<bean id="conversionServiceConverterManagerBean"
class="org.springframework.ldap.odm.typeconversion.impl.ConversionServiceConverterManager">
<constructor-arg ref="conversionService"/>
</bean>
<bean id="defaultObjectDirectoryMapperBean" class="org.springframework.ldap.odm.core.impl.DefaultObjectDirectoryMapper">
<property name="converterManager" ref="conversionServiceConverterManagerBean" />
</bean>
</beans>
Problem solved. I took a second look at the xsd (http://www.springframework.org/schema/ldap/spring-ldap.xsd) and made a modification as follows making use of the
odm-ref
attribute:<ldap:ldap-template id="ldapTemplate" odm-ref="defaultObjectDirectoryMapperBean" context-source-ref="contextSource" >