1)複数のLDAPリポジトリ構成を指定することは可能です。次の例を参照してください。 [お知らせ:これは春ブートライブラリに依存]
@Configuration
@EnableLdapRepositories("com.xxx.repository.ldap")
@EnableConfigurationProperties(LdapProperties.class)
public class LdapConfiguration {
@Autowired
private Environment environment;
@Bean(name="contextSource1")
public LdapContextSource contextSourceTarget(LdapProperties ldapProperties) {
LdapContextSource source = new LdapContextSource();
source.setUserDn(this.properties.getUsername());
source.setPassword(this.properties.getPassword());
source.setBase(this.properties.getBase());
source.setUrls(this.properties.determineUrls(this.environment));
source.setBaseEnvironmentProperties(Collections.<String,Object>unmodifiableMap(this.properties.getBaseEnvironment()));
return source;
}
@Bean
public LdapTemplate ldapTemplate(@Qualifier("contextSource1") LdapContextSource contextSource){
return new LdapTemplate(contextSource);
}
}
あなたは上記LdapConfiguration
を設定するためにapplication.properties
でspring.ldap
接頭辞を使用することができます。利用可能なプロパティは、https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapProperties.javaをチェックすることで確認できます。
@Configuration
@EnableLdapRepositories(basePackages="com.yyy.repository.ldap", ldapTemplateRef="ldapTemplate2")
public class LdapConfiguration2 {
@Autowired
private Environment environment;
@Bean(name="ldapProperties2")
@ConfigurationProperties(prefix="spring.ldap2")
public LdapProperties ldapProperties() {
return new LdapProperties();
}
@Bean(name="contextSource2")
public LdapContextSource contextSourceTarget(@Qualifier("ldapProperties2") LdapProperties ldapProperties) {
LdapContextSource source = new LdapContextSource();
source.setUserDn(this.properties.getUsername());
source.setPassword(this.properties.getPassword());
source.setBase(this.properties.getBase());
source.setUrls(this.properties.determineUrls(this.environment));
source.setBaseEnvironmentProperties(Collections.<String,Object>unmodifiableMap(this.properties.getBaseEnvironment()));
return source;
}
@Bean(name="ldapTemplate2")
public LdapTemplate ldapTemplate(@Qualifier("contextSource2") LdapContextSource contextSource){
return new LdapTemplate(contextSource);
}
}
LdapConfiguration2
はapplication.properties
にspring.ldap2
接頭辞によって設定されます。
2)私はリポジトリを拡張することが解決策だとは思わない。私は@Service
メソッドを作成してリポジトリを反復し、更新を適用することをお勧めします。私は以下の2つのアプローチを提供します。
例1)
@Service
public class UpdateRepositories {
public void updateAllRepositories(LdapUserRepository userRepository1, LdapUserRepository userRepository2) {
// apply updates to userRepository1 and userRepository2
}
}
例2)
@Service
public class UpdateRepositories {
public void updateAllRepositories(ApplicationContext appContext) {
Map<String, LdapRepository> ldapRepositories = appContext.getBeansofType(LdapRepository.class)
// iterate through map and apply updates
}
}
私はこのコードをコンパイルするので、あなたは追加のガイダンスが必要な場合は、何かがオフになっているか、なら、私に知らせていませんでした。
例2では、私はLdapRepository(私が考える最初のインスタンス)を1つだけ取得します。 –
この例は、複数のLdapRepositoryを実装しているかどうかによって異なります。 – ryan2049
2つのエンティティで完全な例を使って答えを追加しました –