Spring 在返回单例 bean 的缓存实例方面时间太长

问题描述 投票:0回答:1

这是我的日志消息。

09:24:21.633 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.security.web.authentication.session.CompositeSessionAuthenticationStrategy#0'
09:24:21.633 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean '(inner bean)#32311ede'
09:24:21.637 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean '(inner bean)#32311ede'
09:24:21.637 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.security.authentication.ProviderManager#0'
09:24:21.638 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.security.authentication.ProviderManager#0'
09:24:21.638 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.security.authentication.AnonymousAuthenticationProvider#0'
09:24:21.638 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.security.authentication.AnonymousAuthenticationProvider#0'
09:24:21.640 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.security.authentication.AnonymousAuthenticationProvider#0' to allow for resolving potential circular references
09:24:21.643 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'org.springframework.security.authentication.AnonymousAuthenticationProvider#0'

09:24:21.643 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.security.authentication.AnonymousAuthenticationProvider#0'
09:24:21.643 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0'
09:24:21.643 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0'
09:24:21.644 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' to allow for resolving potential circular references
09:24:21.647 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0'
09:24:21.647 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.security.authenticationManager'
09:24:21.648 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.security.authenticationManager'
09:24:21.648 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0'
09:24:21.648 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0'
09:24:21.652 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' to allow for resolving potential circular references
09:24:21.700 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'jasyptPasswordEncryption
09:24:21.702 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'tenantDetailsService'

这是我的 Spring Security 配置

以及上述课程

@Service
public class TenantDetailsService implements UserDetailsService {

    @Autowired
    private UserAccountRepo userAccountRepo;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserAccount account = userAccountRepo.findByUsername(username);
        if(account != null){
            List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
            authorities.add(new SimpleGrantedAuthority(account.getRole()));
            return new TenantUserDetails(account.getUsername(),
                    account.getPassword(),authorities,account.getTenantCode());
        }else{
            throw new UsernameNotFoundException("Bad Credentials");
        }
    }
}

还有jasypt密码加密服务

@Service
public class JasyptPasswordEncryptionService implements PasswordEncryptionService,PasswordEncoder{

    private StrongPasswordEncryptor passwordEncryptor = new StrongPasswordEncryptor();

    @Override
    public String encode(CharSequence rawPassword) {
        return passwordEncryptor.encryptPassword(rawPassword.toString());
    }

    @Override
    public boolean matches(CharSequence rawPassword,String  encodedPassword) {
        try{
            return passwordEncryptor.checkPassword(rawPassword.toString(), encodedPassword);
        }catch (EncryptionOperationNotPossibleException encryptionOperationNotPossibleException){
            return  false;
        }
    }
}

问题是我已经花了 30 分钟,构建仍然没有完成,我被困在那两条线上。但是,我将身份验证管理器更改为 springs 默认身份验证管理器并且它起作用了

我的身份验证管理器配置错误吗?

编辑 我现有的配置可以在我的 Windows 机器上运行,但是在 ubuntu 14.04 上则不行

java spring spring-mvc spring-security
1个回答
0
投票

就我而言,问题是我的代码陷入了永恒的循环。修复循环就解决了问题

© www.soinside.com 2019 - 2024. All rights reserved.