회원가입 시 아래 에러가 남
에러가 난 상태의 코드..
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-09-13T10:26:55.675+09:00 ERROR 11084 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'homeController' defined in file [C:\Users\weaver-gram-002\IdeaProjects\first\build\classes\java\main\com\example\first\controller\HomeController.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'userServiceImpl' defined in file [C:\Users\weaver-gram-002\IdeaProjects\first\build\classes\java\main\com\example\first\service\UserServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'homeMapper' defined in file [C:\Users\weaver-gram-002\IdeaProjects\first\build\classes\java\main\com\example\first\mapper\HomeMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory': Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception with message: Failed to parse mapping resource: 'file [C:\Users\weaver-gram-002\IdeaProjects\first\build\resources\main\mybatis\mapper\HomeMapper.xml]'
매퍼 쪽에서 에러가 나는 거 같음.
sqlSessionFactory를 주입하는데 실패했다고 해서
아래와 같이 주입을 해봤다.
package com.example.first.service;
import com.example.first.dto.UserDto;
import com.example.first.dto.UserRequestDto;
import com.example.first.entity.User;
import com.example.first.mapper.HomeMapper;
import lombok.RequiredArgsConstructor;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService{
private final HomeMapper homeMapper;
private final SqlSessionTemplate sqlSessionTemplate;
// private final BCryptPasswordEncoder encoder;
@Autowired
public UserServiceImpl(HomeMapper homeMapper, SqlSessionTemplate sqlSessionTemplate) {
this.homeMapper = homeMapper;
this.sqlSessionTemplate = sqlSessionTemplate;
}
@Override
public void signUp(UserDto userDto) {
homeMapper.signUp(userDto);
}
@Override
public void login(UserRequestDto userRequestDto) {
Long userId = userRequestDto.getUserId();
User foundUser = homeMapper.findByUserId(userId);
if (userId == foundUser.getUserId()) {
homeMapper.login(userRequestDto);
}
}
// @Override
// public UserResponseDto personalInfo() {
// return homeMapper.personalInfo();
// }
@Override
public boolean isUsernameUnique(String username) {
return homeMapper.isUsernameUnique(username);
}
}
동일한 에러가 계속 뜬다 ,,
아래는 코드ㅜㅜ
https://github.com/hyeonju-kim/first_project
ㅡㅡㅡ
1차 시도 : 마이바티스는 스프링부트 2와 써야한다는 글을 보고 스프링버전을 2.6.7로 내려줌
java.lang.NoClassDefFoundError: org/springframework/aot/AotDetector
at org.mybatis.spring.mapper.ClassPathMapperScanner.<init>(ClassPathMapperScanner.java:91) ~[mybatis-spring-3.0.2.jar:3.0.2]
at org.mybatis.spring.mapper.MapperScannerConfigurer.postProcessBeanDefinitionRegistry(MapperScannerConfigurer.java:363) ~[mybatis-spring-3.0.2.jar:3.0.2]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311) ~[spring-context-5.3.19.jar:5.3.19]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:142) ~[spring-context-5.3.19.jar:5.3.19]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746) ~[spring-context-5.3.19.jar:5.3.19]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564) ~[spring-context-5.3.19.jar:5.3.19]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.7.jar:2.6.7]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[spring-boot-2.6.7.jar:2.6.7]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[spring-boot-2.6.7.jar:2.6.7]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-2.6.7.jar:2.6.7]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-2.6.7.jar:2.6.7]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.7.jar:2.6.7]
at co m.example.first.FirstApplication.main(FirstApplication.java:12) ~[main/:na]
Caused by: java.lang.ClassNotFoundException: org.springframework.aot.AotDetector
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
... 13 common frames omitted
UnsatisfiedDependencyException 에러가 사라지고 새로운 NoClassDefFoundError 에러가 생김
NoClassDefFoundError 에러는 컴파일 시점에 존재했던 클래스가 런타임에 존재하지 않으면 발생하는 에러라고 한다..
첫번째 시도 :
패키지 경로가 잘못될 경우 , 이런 문제가 발생할 수도 있다고 하여,
mapper.xml의 패키지 경로를 살펴봄
<!--회원가입-->
<mapper namespace="com.example.first.mapper.HomeMapper">
<select id="signUp" parameterType="com.example.first.dto.UserRequestDto">
INSERT INTO postgres.first_project.users (user_email, user_name, user_nickname, user_password, user_password_confirm, user_phone_number)
VALUES ( #{email}, #{username}, #{nickname}, #{password}, #{password}, #{phoneNumber})
</select>
여기서 이 경로가 잘못되어 있었다.
<select id="signUp" parameterType="com.example.first.dto.UserRequestDto">
아래로 수정했다.
<select id="signUp" parameterType="com.example.first.dto.UserDto">
안됨ㅎ
두번째 시도 :
마이바티스 의존성 버전을 3.0.2 -> 2.2.2로 낮춤
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.2'
해결!!!!ㅠㅠ
https://yangbox.tistory.com/117
https://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java
'Back-end > java' 카테고리의 다른 글
카카오 주소 검색 api 로 회원가입 시 주소 입력하기 & 에러 (0) | 2023.09.13 |
---|---|
Path with "WEB-INF" or "META-INF 에러 (0) | 2023.09.13 |
Illegal invocation 에러 (415에러) (0) | 2023.09.12 |
[리눅스]리눅스 서버에서 톰캣을 강제종료 하는 방법 (Web server failed to start. Port 8080 was already in use. 해결) (0) | 2023.06.27 |
[혼공자][챕터13-1] 컬렉션 프레임워크 (1) | 2022.12.14 |