2017-03-12 1 views
0

스프링 부트에서 역할을 가진 간단한 로그인을 만들려고합니다. 내가 들어갈 login.html을 통해 로그인을 시도 할 때마다봄 부팅 인증에서 스택 오버플로

package com.codecool.domain; 


import lombok.Data; 
import lombok.extern.slf4j.Slf4j; 

import javax.persistence.*; 
import java.util.Set; 

@Data 
@Entity 
@Table(name="role") 
@Slf4j 
public class Role { 

    @Id 
    @GeneratedValue(strategy=GenerationType.IDENTITY) 
    private Long id; 

    private String name; 

    @ManyToMany(mappedBy = "roles", fetch=FetchType.EAGER) 
    private Set<User> users; 

    private Role(){} 

    public Role(String name){ 
     this.name = name; 
    } 
} 

:

package com.codecool.domain; 


import lombok.Data; 
import lombok.extern.slf4j.Slf4j; 

import javax.persistence.*; 
import java.util.Set; 

@Data 
@Entity 
@Table(name="users") 
@Slf4j 
public class User { 

@Id 
@Column(name="user_id", unique = true) 
@GeneratedValue(strategy=GenerationType.IDENTITY) 
private Long id; 

@Column(name="email") 
private String email; 

@Column(name="password") 
private String password; 

@ManyToMany(fetch=FetchType.EAGER) 
@JoinTable(name="user_role", joinColumns =   @JoinColumn(name="user_id"), inverseJoinColumns = @JoinColumn(name="role_id")) 
private Set<Role> roles; 

private User(){} 

public User(String email, String password, Set<Role> roles) { 
    this.email = email; 
    this.password = password; 
    this.roles = roles; 
} 

}

... 그리고 역할 클래스 :

나는 사용자 클래스가 다음과 같은 오류 메시지가 포함 된 무한 루프 :

2017-03-12 13 : 26 : 17.872 INFO 8794 --- [io-8080-exec-1 0] o.h.hi.QueryTranslatorFactoryInitiator : HHH000397 : ASTQueryTranslatorFactory 사용 최대 절전 모드 : user0_.user_id를 user_id1_2_, user0_.email을 email2_2_, user0_.password를 password3_2_ 사용자 user0_에서 선택하십시오. 여기서 user0_.email =? 최대 절전 모드 : role0_.user_id를 user_id1_1_0_, roles0_.role_id를 role_id2_1_0_, role1_.id를 id1_0_1_, role1_.name을 name2_0_1_으로 user_role roles0_ 내부 결합 역할 role1_ on roles0_.role_id = role1_.id 여기서 roles0_.user_id =? 최대 절전 모드 : 사용자 0_.role_id를 role_id2_1_0_, 사용자 0_.user_id를 user_id1_1_0, user1_.user_id를 user_id1_2_1_, user1_.email을 email2_2_1_, user1_.password를 password3_2_1_ user_role users0_ 내부 참여 사용자 user1_ users0_.user_id = user1_.user_id users0_ .role_id =? 최대 절전 모드 : role0_.user_id를 user_id1_1_0_, roles0_.role_id를 role_id2_1_0_, role1_.id를 id1_0_1_, role1_.name을 name2_0_1_으로 user_role roles0_ 내부 결합 역할 role1_ on roles0_.role_id = role1_.id 여기서 roles0_.user_id =? 최대 절전 모드 : 사용자 0_.role_id를 role_id2_1_0_, 사용자 0_.user_id를 user_id1_1_0, user1_.user_id를 user_id1_2_1_, user1_.email을 email2_2_1_, user1_.password를 password3_2_1_ user_role users0_ 내부 참여 사용자 user1_ users0_.user_id = user1_.user_id users0_ .role_id =? 최대 절전 모드 : role0_.user_id를 user_id1_1_0_, roles0_.role_id를 role_id2_1_0_, role1_.id를 id1_0_1_, role1_.name을 name2_0_1_으로 user_role roles0_ 내부 결합 역할 role1_ on roles0_.role_id = role1_.id 여기서 roles0_.user_id =? 최대 절전 모드 : 사용자 0_.role_id를 role_id2_1_0_, 사용자 0_.user_id를 user_id1_1_0, user1_.user_id를 user_id1_2_1_, user1_.email을 email2_2_1_, user1_.password를 password3_2_1_ user_role users0_ 내부 참여 사용자 user1_ users0_.user_id = user1_.user_id users0_ .role_id =? 최대 절전 모드 : role0_.user_id를 user_id1_1_0_, roles0_.role_id를 role_id2_1_0_, role1_.id를 id1_0_1_, role1_.name을 name2_0_1_으로 user_role roles0_ 내부 결합 역할 role1_ on roles0_.role_id = role1_.id 여기서 roles0_.user_id =? 최대 절전 모드 : 사용자 0_.role_id를 role_id2_1_0_, 사용자 0_.user_id를 user_id1_1_0, user1_.user_id를 user_id1_2_1_, user1_.email을 email2_2_1_, user1_.password를 password3_2_1_ user_role users0_ 내부 참여 사용자 user1_ users0_.user_id = user1_.user_id users0_ .role_id =?

내가 누락 된 아이디어가 있습니까?

답변

2

당신이 RestController에서 개체를 반환하려는 경우, 객체 직렬화는 예를 들어, 사용자 또는 역할이

@Data 
@Entity 
@Table(name="role") 
@Slf4j 
public class Role { 

    @Id 
    @GeneratedValue(strategy=GenerationType.IDENTITY) 
    private Long id; 

    private String name; 

    @ManyToMany(mappedBy = "roles", fetch=FetchType.EAGER) 
    @JsonIgnore 
    private Set<User> users; 

    private Role(){} 

    public Role(String name){ 
     this.name = name; 
    } 
} 
Role.java

사용자를 무시 jsonignore 할이 문제를 직렬화 .FOR 해결하기 위해 잭슨을 사용 .Spring JSON으로
0

사용 지연로드

@ManyToMany(mappedBy = "roles", fetch=FetchType.LAZY) 
private Set<User> users; 

그리고 Roleusers을 가지는 것은 좋은 생각이 아니다. 이 필드를 제거하는 것이 좋습니다.