강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

임지수님의 프로필 이미지
임지수

작성한 질문수

스프링부트 mysql 연결

작성

·

633

0

https://www.inflearn.com/questions/913307/%EC%8A%A4%ED%94%84%EB%A7%81%EB%B6%80%ED%8A%B8-mysql-%EC%97%B0%EA%B2%B0%EC%9D%80-%ED%96%88%EB%8A%94%EB%8D%B0%EC%9A%94

 

전글에 올렸던 내용에서 덧붙이자면,

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

이런 오류가 나서 log4jdbc.log4j2.properties

log4jdbc.drivers=com.mysql.cj.jdbc.Driver
log4jdbc.auto.load.popular.drivers=false

에 코드 추가했어요.

그래서 지금

스크린샷 2023-06-25 173107.png밑에 저 오류가 남았는데 저건 어떻게 해결해야하는지 모르겠습니다..

org.springframework.boot.devtools.restart.SilentExitExceptionHandler$SilentExitException
	at org.springframework.boot.devtools.restart.SilentExitExceptionHandler.exitCurrentThread(SilentExitExceptionHandler.java:92)
	at org.springframework.boot.devtools.restart.Restarter.immediateRestart(Restarter.java:180)
	at org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:164)
	at org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:554)
	at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationStartingEvent(RestartApplicationListener.java:90)
	at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationEvent(RestartApplicationListener.java:50)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
	at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:79)
	at org.springframework.boot.SpringApplicationRunListeners.lambda$starting$0(SpringApplicationRunListeners.java:56)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120)
	at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:56)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:298)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)
	at carrot.app.AppApplication.main(AppApplication.java:13)

 

답변 1

0

안녕하세요, 인프런 AI 인턴입니다.

스프링부트에서 MySQL 연결 시 오류가 발생하고 있다면, 문제가 발생한 부분에서 로그를 확인해보는 것이 도움이 될 수 있습니다. 예를 들어, 「Loading class `com.mysql.jdbc.Driver’. This is deprecated.」에러는 MySQL 드라이버 클래스명이 바뀌어서 발생하는 문제로 보입니다.

이 에러를 해결하기 위해서는, 애너테이션 @SpringBootApplication 이 붙은 클래스에서 다음과 같이 드라이버 클래스를 등록하면 됩니다.

@Bean
public DataSource dataSource() {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Seoul&useSSL=false&allowPublicKeyRetrieval=true");
    dataSource.setUsername("사용자명");
    dataSource.setPassword("비밀번호");
    return dataSource;
}

다만, Spring Boot 2.0 이후 버전에서는 spring.datasource.driver-class-name 속성을 사용하여 드라이버 클래스를 등록하는 것이 권장되고 있습니다.

추가적으로, 에러 메시지 「org.springframework.boot.devtools.restart.SilentExitExceptionHandler$SilentExitException at… 」와 같은 내용은 스프링부트 Devtools 에러 메시지인 것으로 보입니다. 이 에러가 발생하는 경우, Devtools가 원활히 작동하지 않아서 발생하는 것이므로 버전을 확인해보시고, 필요하다면 업데이트를 진행하시기 바랍니다.

마지막으로, 오류를 해결하지 못하신 경우에는 더 자세한 로그와 함께 새로운 질문을 작성하여 문의해 주시기 바랍니다.

이상입니다. 좋은 하루 보내세요 :)

임지수님의 프로필 이미지
임지수

작성한 질문수

질문하기