작성
·
317
0
User라는 entity에서 AuthorityDTO라는 클래스로 변환을 하려고 하는 데 에러가 나서 원인을 혹시 아시나요?
bean, fields, constructor 전부 같은 에러가 나네요.
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [com.illunex.invest.user.persistence.entity.User] to type [com.illunex.invest.api.core.user.dto.AuthorityDTO]
public List<AuthorityDTO> findByCompanyIdx(Long companyIdx) {
QUser user = QUser.user;
return queryFactory.select(Projections.bean(AuthorityDTO.class
, user.id
, user.username
, user.name
, user.authorities
, user.profileImg
, user.companyIdx))
.from(user)
.where(user.companyIdx.eq(companyIdx))
.fetch();
}
@NoArgsConstructor
@AllArgsConstructor
@Getter @Setter
public class AuthorityDTO {
private Long id;
private String username;
private String name;
//private Set<RoleDTO> authorities = new HashSet<>();
private String profileImg;
private Long companyIdx;
}
@Entity
@Table(name = "user"
, indexes = {
@Index(name = "IDX_USERNAME", unique = true, columnList = "username"),
@Index(name = "IDX_COMPANY_IDX", columnList = "companyIdx")
})
@NoArgsConstructor
@AllArgsConstructor
@Getter @Setter
@Builder
public class User implements UserInterface {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false, updatable = false)
private Long id;
@Column(nullable = false, unique = true)
private String username;
@Column(nullable = false)
private String password;
private String name;
@ManyToMany(cascade=CascadeType.ALL)
@JoinTable(name = "user_role",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "role_id"))
private Set<Role> authorities = new HashSet<>();
private String profileImg;
private String vender;
private Long companyIdx;
private Boolean certification = false;
private String token;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.DETACH, mappedBy = "user")
private List<Signature> signatures = new ArrayList<>();
public static User createUser(String username, String password, String name, String vender, String token, Long companyIdx) {
return getUserBuilder(username, password, name, vender, token, companyIdx)
.authorities(Role.initRoles())
.build();
}
public static User createCompanyAdminUser(String username, String password, String name, String vender, String token, Long companyIdx) {
return getUserBuilder(username, password, name, vender, token, companyIdx)
.authorities(Role.companyAdminRoles())
.build();
}
private static UserBuilder getUserBuilder(String username, String password, String name, String vender, String token, Long companyIdx) {
return User.builder()
.username(username)
.password(encodePassword(password))
.name(name)
.vender(vender)
.certification(false)
.token(token)
.companyIdx(companyIdx);
}
public static String encodePassword(String password) {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
return encoder.encode(password);
}
public static boolean matchPassword(String prePassword, String inputPassword) {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
return encoder.matches(inputPassword, prePassword);
}
@Override
public Collection<Role> getAuthorities() {
return authorities;
}
@Override
public boolean isAccountNonExpired() {
return true;
}
@Override
public boolean isAccountNonLocked() {
return true;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
return true;
}
}
답변 1
0
안녕하세요. 형진님
Querydsl을 사용했는데, 오류는 Spring오류가 나서요. 좀 봐야할 것 같아요.
똑같은 오류를 재현할 수 있는 테스트를 작성해서 전체 프로젝트를 압축해서 올려주세요.
감사합니다.