I am writing a Spring LDAP application and I have to set the authentication strategy for my ContextSource. I would like to do this in my beans XML file. The JavaDoc for ContextSource says that it has a setter method called
setAuthenticationStrategy(
DirContextAuthenticationStrategy authenticationStrategy
)
To invoke 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>
That is to say, what exactly determines the invocation of the method setAuthenticationStrategy? Is it that my property name is authenticationStrategy? Does Spring automatically translate property names to the appropriate setter method?
Your suspicion is correct: Spring translates property names to setter methods.
The bean you are using as the argument is of type
DefaultTlsDirContextAuthenticationStrategy, and the method accepts an object of typeDirContextAuthenticationStrategy, soDefaultTlsDirContextAuthenticationStrategymust be a subclass of implementor ofDirContextAuthenticationStrategy.