要动态重新加载我的应用配置,我决定试用Apache公共资源 FileChangedReloadingStrategy
我正在使用Spring Security进行Ldap身份验证,在使用immutable
之前,我保留了FileChangedReloadingStrategy
的单个实例,如:
LdapTemplate
但是,由于现在我正在尝试提供动态配置更改,我每次都必须创建一个新的ldap连接(以便可以使用已修改的配置,如果有的话)。但这会影响性能。
@Component
public class LdapAuthenticationProvider implements AuthenticationProvider{
private LdapTemplate ldapTemplate;
private LdapContextSource contextSource;
@PostConstruct
public void init() {
contextSource = new LdapContextSource();
contextSource.setUrl(LDAP_CONFIG_BASE_URL);
contextSource.setAnonymousReadOnly(LDAP_CONFIG_IS_ANONYMOUS);
contextSource.afterPropertiesSet();
ldapTemplate = new LdapTemplate(contextSource);
}
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
// use ldapTemplate to do authentication
}
所以我的问题是,可以避免在性能和提供动态配置之间进行权衡吗?是否有非Springboot方法来刷新bean?
注意::我发现使用Springboot,您可以使用Spring-cloud,其中有方法可以刷新bean但是我没有使用Springboot并且找不到合适的文档来使用spring-没有Springboot的云,所以我坚持使用Apache的FileChangedReloadingStrategy。
修改 我正面临性能问题,其中ldap连接池有时会变满,并且由于此而导致连接超时错误。