且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在SpringSecurity Bean中模拟自定义UserServiceDetails进行单元测试?

更新时间:2023-10-09 18:11:52

我认为您应该使用 @Profile UserDetailesService 是一个接口,用于创建 UserDetailesService 的两个实现,一个用于测试,另一个用于其余的情况

I think you should use @Profile, UserDetailesService is an interface creates two implementation of UserDetailesService, one for test and another for the rest of the case

@Component
@Profile("test")
public class UserDetailesServiceTestImpl implements UserDetailesService{


}

@Component
@Profile("!test")
public class UserDetailesServiceImpl implements UserDetailesService{


}