org.hibernate.LazyInitializationException: could not initialize proxy [com.murilo.forum.modelo.Usuario#1] - no Session
https://github.com/MuriloRicardoPrincipe/SpringSecurity/commits/main
org.hibernate.LazyInitializationException: could not initialize proxy [com.murilo.forum.modelo.Usuario#1] - no Session
https://github.com/MuriloRicardoPrincipe/SpringSecurity/commits/main
Resolvido o erro estava nessa classe
private void autenticarCliente(String token) {
Long idUsuario = tokenService.getIdUsuario(token);
Usuario usuario = usuarioRepository.ById(idUsuario);// nao sei por que mas meu atalho so jogava essa linha de codigo
UsernamePasswordAuthenticationToken authentication = new
UsernamePasswordAuthenticationToken(usuario, null,usuario.getAuthorities() );
SecurityContextHolder.getContext().setAuthentication(authentication);
}
Linha certa
private void autenticarCliente(String token) {
Long idUsuario = tokenService.getIdUsuario(token);
Usuario usuario = usuarioRepository.findById(idUsuario).get();
UsernamePasswordAuthenticationToken authentication = new
UsernamePasswordAuthenticationToken(usuario, null,usuario.getAuthorities() );
SecurityContextHolder.getContext().setAuthentication(authentication);
}