java - Spring does not load LDAP-XML config file -
i have prototype spring application play spring-security , ldap. application works internal ldap-server. when want define individual connection xml-config doesn't work. more specific: ldaptemplate should instantiated xml-config stays null-object. here code:
public class userrepo { @autowired private ldaptemplate ldaptemplate; //stays null public static final string base_dn = "dc=springframework,dc=org"; //this works, not desired: public userrepo() { // final genericxmlapplicationcontext appcontext = new genericxmlapplicationcontext("classpath:ldap.xml"); // appcontext.refresh(); // ldaptemplate = (ldaptemplate)appcontext.getbean(ldaptemplate.class); // ldapcontextsource lcs = new ldapcontextsource(); // lcs.seturl("ldap://127.0.0.1:389/"); // lcs.setuserdn(base_dn); // lcs.setdirobjectfactory(defaultdirobjectfactory.class); // lcs.setanonymousreadonly(true); // lcs.afterpropertiesset(); // ldaptemplate = new ldaptemplate(lcs); }
my config looks this:
<?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: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"> <ldap:context-source id="contextsource" url="ldap://localhost:389" base="dc=example,dc=com" username="cn=manager" password="secret" /> <ldap:ldap-template id="ldaptemplate" /> <bean id="userrepo" class="user.userrepo"> <property name="ldaptemplate" ref="ldaptemplate" /> </bean> </beans>
i have set ldap.xml 1 time in src-dir , time in ressource-dir, both didn't work.
i hope can tell me i'm doing wrong.
add @component annotation userrepo class , proper annotation-config (or component-scan element if required). since commented-out code works, ldaptemplate bean created succesfully, , injected because utilize genericxmlapplicationcontext. test annotations need annotationconfigapplicationcontext instead.
java xml spring
No comments:
Post a Comment