用SpringJava配置共同配置嵌入式ApacheDS服务器
因此,我有一个现有的配置文件,用于配置用SpringJava配置共同配置嵌入式ApacheDS服务器,java,spring,apacheds,Java,Spring,Apacheds,因此,我有一个现有的配置文件,用于配置org.springframework.ldap.core.ContextSource @Configuration public class LdapContextConfig { @Inject private LdapProperties ldapProperties; @Bean public ContextSource contextSource() { final TransactionAwar
org.springframework.ldap.core.ContextSource
@Configuration
public class LdapContextConfig {
@Inject
private LdapProperties ldapProperties;
@Bean
public ContextSource contextSource() {
final TransactionAwareContextSourceProxy transactionAwareContextSourceProxy =
new TransactionAwareContextSourceProxy(poolingContextSource());
return transactionAwareContextSourceProxy;
}
@Bean
public PoolingContextSource poolingContextSource() {
final PoolingContextSource poolingContextSource = new MutablePoolingContextSource();
poolingContextSource.setContextSource(ldapContextSource());
poolingContextSource.setDirContextValidator(new DefaultDirContextValidator());
poolingContextSource.setTestOnBorrow(true); //default false
return poolingContextSource;
}
@Bean
public LdapContextSource ldapContextSource() {
final LdapContextSource ldapContextSource = new LdapContextSource();
ldapContextSource.setUrl(ldapProperties.getUrl());
ldapContextSource.setBase(ldapProperties.getBase());
ldapContextSource.setUserDn(ldapProperties.getUserDn());
ldapContextSource.setPassword(ldapProperties.getPassword());
return ldapContextSource;
}
}
@Configuration
public class EmbeddedLdapConfig {
@Bean
public DirectoryService getDirectoryService() throws Exception {
final DirectoryService directoryService = new DefaultDirectoryService();
//other config
return directoryService;
}
}
@Inject
private DirectoryService directoryService;
@Bean
public LdapContextSource embeddedLdapContextSource() {
final LdapContextSource embeddedLdapContextSource = /*convert DirectoryService to LdapContextSource*/;
return embeddedLdapContextSource;
}
这使用自定义的LdapProperties
类在部署应用程序时从属性文件中提取url、base、userDn和密码
现在,我正在尝试设置一个嵌入式ApacheDS服务器,用于集成测试
我有另一个配置文件来设置ApacheDSDirectoryService
@Configuration
public class LdapContextConfig {
@Inject
private LdapProperties ldapProperties;
@Bean
public ContextSource contextSource() {
final TransactionAwareContextSourceProxy transactionAwareContextSourceProxy =
new TransactionAwareContextSourceProxy(poolingContextSource());
return transactionAwareContextSourceProxy;
}
@Bean
public PoolingContextSource poolingContextSource() {
final PoolingContextSource poolingContextSource = new MutablePoolingContextSource();
poolingContextSource.setContextSource(ldapContextSource());
poolingContextSource.setDirContextValidator(new DefaultDirContextValidator());
poolingContextSource.setTestOnBorrow(true); //default false
return poolingContextSource;
}
@Bean
public LdapContextSource ldapContextSource() {
final LdapContextSource ldapContextSource = new LdapContextSource();
ldapContextSource.setUrl(ldapProperties.getUrl());
ldapContextSource.setBase(ldapProperties.getBase());
ldapContextSource.setUserDn(ldapProperties.getUserDn());
ldapContextSource.setPassword(ldapProperties.getPassword());
return ldapContextSource;
}
}
@Configuration
public class EmbeddedLdapConfig {
@Bean
public DirectoryService getDirectoryService() throws Exception {
final DirectoryService directoryService = new DefaultDirectoryService();
//other config
return directoryService;
}
}
@Inject
private DirectoryService directoryService;
@Bean
public LdapContextSource embeddedLdapContextSource() {
final LdapContextSource embeddedLdapContextSource = /*convert DirectoryService to LdapContextSource*/;
return embeddedLdapContextSource;
}
现在我正在寻找一种将ApacheDSDirectoryService
映射到SpringLdapContextSource
的方法
@Configuration
public class LdapContextConfig {
@Inject
private LdapProperties ldapProperties;
@Bean
public ContextSource contextSource() {
final TransactionAwareContextSourceProxy transactionAwareContextSourceProxy =
new TransactionAwareContextSourceProxy(poolingContextSource());
return transactionAwareContextSourceProxy;
}
@Bean
public PoolingContextSource poolingContextSource() {
final PoolingContextSource poolingContextSource = new MutablePoolingContextSource();
poolingContextSource.setContextSource(ldapContextSource());
poolingContextSource.setDirContextValidator(new DefaultDirContextValidator());
poolingContextSource.setTestOnBorrow(true); //default false
return poolingContextSource;
}
@Bean
public LdapContextSource ldapContextSource() {
final LdapContextSource ldapContextSource = new LdapContextSource();
ldapContextSource.setUrl(ldapProperties.getUrl());
ldapContextSource.setBase(ldapProperties.getBase());
ldapContextSource.setUserDn(ldapProperties.getUserDn());
ldapContextSource.setPassword(ldapProperties.getPassword());
return ldapContextSource;
}
}
@Configuration
public class EmbeddedLdapConfig {
@Bean
public DirectoryService getDirectoryService() throws Exception {
final DirectoryService directoryService = new DefaultDirectoryService();
//other config
return directoryService;
}
}
@Inject
private DirectoryService directoryService;
@Bean
public LdapContextSource embeddedLdapContextSource() {
final LdapContextSource embeddedLdapContextSource = /*convert DirectoryService to LdapContextSource*/;
return embeddedLdapContextSource;
}
我已将DirectoryService
注入我的LdapContextConfig
中,并为嵌入的LdapContextSource
创建了一个单独的@Bean
@Configuration
public class LdapContextConfig {
@Inject
private LdapProperties ldapProperties;
@Bean
public ContextSource contextSource() {
final TransactionAwareContextSourceProxy transactionAwareContextSourceProxy =
new TransactionAwareContextSourceProxy(poolingContextSource());
return transactionAwareContextSourceProxy;
}
@Bean
public PoolingContextSource poolingContextSource() {
final PoolingContextSource poolingContextSource = new MutablePoolingContextSource();
poolingContextSource.setContextSource(ldapContextSource());
poolingContextSource.setDirContextValidator(new DefaultDirContextValidator());
poolingContextSource.setTestOnBorrow(true); //default false
return poolingContextSource;
}
@Bean
public LdapContextSource ldapContextSource() {
final LdapContextSource ldapContextSource = new LdapContextSource();
ldapContextSource.setUrl(ldapProperties.getUrl());
ldapContextSource.setBase(ldapProperties.getBase());
ldapContextSource.setUserDn(ldapProperties.getUserDn());
ldapContextSource.setPassword(ldapProperties.getPassword());
return ldapContextSource;
}
}
@Configuration
public class EmbeddedLdapConfig {
@Bean
public DirectoryService getDirectoryService() throws Exception {
final DirectoryService directoryService = new DefaultDirectoryService();
//other config
return directoryService;
}
}
@Inject
private DirectoryService directoryService;
@Bean
public LdapContextSource embeddedLdapContextSource() {
final LdapContextSource embeddedLdapContextSource = /*convert DirectoryService to LdapContextSource*/;
return embeddedLdapContextSource;
}
是否可以通过某种方式从ApacheDSDirectoryService
获取LdapContextSource
?如果是这样的话,我该怎么做呢