728x90
@SpringbootTest 오류
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use
@ContextConfiguration or @SpringBootTest(classes=...) with your test
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name
'com.TheCp.repository.MemberRepositoryTest': Unsatisfied dependency expressed through field
'memberRepository': No qualifying bean of type
'com.TheCp.repository.MemberRepository'
available: expected at least 1 bean which qualifies as autowire candidate.
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
- 구성오류
- 메인 클래스와 내부에 있어야할 Repository가 경로상 밖으로 나와있어서 Bean을 찾지 못해 발생한 오류.
- autowired 로 빈을 인식시키는 것은 맞음
JPA 매핑 오류
@Test
public void signUpUsers() {
// Given
Users Users = com.ham.hp.thecp.domain.Users.builder()
.userId(1L)
.userPassword("password")
.userEmail("test@example.com")
.userName("Test User")
.userPhone("123-456-7890")
.userBirthDate(LocalDateTime.now().minusYears(25))
.userCreateDate(LocalDateTime.now())
.userRole(UserRole.Active)
.build();
// When
Users savedUsers = UsersRepository.save(Users);
// Then
Assertions.assertNotNull(savedUsers.getUserId());
Assertions.assertEquals(Users.getUserEmail(), savedUsers.getUserEmail());
}
Hibernate:
select
m1_0.userid,
m1_0.user_birth_date,
m1_0.create_date,
m1_0.user_email,
m1_0.user_name,
m1_0.user_password,
m1_0.user_phone,
m1_0.status
from
member m1_0
where
m1_0.userid=?
Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
- 해당 Junit5 를 사용한 테스팅 코드에서 아래같은 오류가 발생했음
- Table 이름과, select 컬럼명들이 내 DB 컬럼명과 매칭이되지 않았음
@Entity
@Getter
@Builder
@Table(name = "users")
@NoArgsConstructor
public class Users {
@Id
@Column(name = "UserID")
private Long userId;
@Column(name = "UserPassword")
private String userPassword;
@Column(name = "UserEmail")
private String userEmail;
@Column(name = "UserName")
private String userName;
@Column(name = "UserPhone")
private String userPhone;
@Column(name = "UserBirthdate")
private LocalDateTime userBirthDate;
@Column(name = "createdate")
private LocalDateTime userCreateDate;
@Column(name = "Status")
@Enumerated(EnumType.STRING)
private UserRole userRole;
@Builder
public Users(Long userId, String userPassword, String userEmail, String userName, String userPhone, LocalDateTime userBirthDate, LocalDateTime userCreateDate, UserRole userRole) {
this.userId = userId;
this.userPassword = userPassword;
this.userEmail = userEmail;
this.userName = userName;
this.userPhone = userPhone;
this.userBirthDate = userBirthDate;
this.userCreateDate = userCreateDate;
this.userRole = userRole;
}
}
- 내 Users.class Entitiy 파일이다. JPA를 이용할때는 자동으로 매핑되기 때문에 @Column 어노테이션의 (name = “”) 속성으로 매핑할 이름을 정할 수 있음
- 대-소문자를 구별하지 않기 때문에 위의 형식은 결국 @Column(name = “”) 속성이 작동하지 않았음
- 대문자 → 모두 소문자로 변경 한 후 테스트 통과
728x90
'SpringBoot > 프로젝트 게시판 만들기' 카테고리의 다른 글
OAuth 2.0 이라는게 뭘까? (0) | 2023.08.23 |
---|---|
Spring Security WebSecurityConfigurerAdapter (0) | 2023.07.24 |
React 와 Spring 환경 구성 세팅 (0) | 2023.07.13 |
Spring 쇼핑몰 프로젝트 - MySQL 연동하기 (0) | 2023.07.12 |
Spring 쇼핑몰 프로젝트 (-) 수정 (0) | 2023.07.12 |