Java – Spring / LDAP — calling setter method in bean configuration
I'm writing a spring LDAP application and I have to set an authentication policy for contextsource I want to do this in my bean XML file Javadoc for contextsource says it has a method called setter
setAuthenticationStrategy( DirContextAuthenticationStrategy authenticationStrategy )
To call this setter from my beans file, is the following XML sufficient?
<bean id="authStrategy" class="org.springframework...DefaultTlsDirContextAuthenticationStrategy"> ... </bean> <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource"> <property name="url" ... /> <property name="base" ... /> ... <property name="authenticationStrategy" ref="authStrategy" /> </bean>
In other words, what determines the call of setauthenticationstrategy method? Is my attribute name authenticationstrategy? Will spring automatically convert the property name to the appropriate setter method?
Solution
Your suspicion is correct: Spring converts property names to setter methods
The type of the bean you use as a parameter is defaulttlsdircontextauthenticationstrategy, and this method accepts objects of type dircontextauthenticationstrategy. Therefore, defaulttlsdircontextauthenticationstrategy must be a subclass of the implementer of dircontextauthenticationstrategy