SpringBoot: reslove circular dependancie

- remove lazy load
This commit is contained in:
djmil 2023-08-26 22:29:35 +02:00
parent 25b0b34b8d
commit 23560c8326
3 changed files with 14 additions and 22 deletions

View File

@ -1,7 +1,5 @@
package djmil.cordacheckers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
@ -12,13 +10,13 @@ import org.springframework.stereotype.Service;
@Service
public class ApiUserDetailsService implements UserDetailsService {
@Autowired
@Lazy
private PasswordEncoder encoder;
private final PasswordEncoder encoder;
private final ApiUserShortHashService apiUserShortHash;
@Autowired
@Lazy
ApiUserShortHashService apiUserShortHash;
public ApiUserDetailsService(PasswordEncoder encoder, ApiUserShortHashService apiUserShortHash) {
this.encoder = encoder;
this.apiUserShortHash = apiUserShortHash;
}
@Override
public ApiUserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

View File

@ -1,7 +1,5 @@
package djmil.cordacheckers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@ -13,12 +11,13 @@ import org.springframework.stereotype.Service;
@Service
public class CustomAuthenticationProvider implements AuthenticationProvider {
@Autowired
@Lazy
private PasswordEncoder encoder;
private final PasswordEncoder encoder;
private final ApiUserDetailsService userDetailsService;
@Autowired
private ApiUserDetailsService userDetailsService;
public CustomAuthenticationProvider(PasswordEncoder encoder, ApiUserDetailsService userDetailsService) {
this.userDetailsService = userDetailsService;
this.encoder = encoder;
}
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {

View File

@ -1,6 +1,5 @@
package djmil.cordacheckers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
@ -22,11 +21,7 @@ public class SecurityConfig {
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}
@Autowired
CustomAuthenticationProvider authenticationProvider;
@Autowired
public void configure(AuthenticationManagerBuilder auth) throws Exception {
public void configure(AuthenticationManagerBuilder auth, CustomAuthenticationProvider authenticationProvider) throws Exception {
auth.authenticationProvider(authenticationProvider);
}