mysql연동 코드 작업 후 빌드가 되지않고 아래 에러가 발생하고있다
java.lang.IllegalStateException: Failed to load ApplicationContext for [WebMergedContextConfiguration@688d619c testClass = com.sdemo1.SdemoApplicationTest, locations = [], classes = [com.sdemo1.SdemoApplication], contextInitializerClasses = [], activeProfiles = [], propertySourceDescriptors = [], propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"], contextCustomizers = [org.springframework.boot.test.autoconfigure.OnFailureConditionReportContextCustomizerFactory$OnFailureConditionReportContextCustomizer@604f2bd2, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@52066604, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@5f9678e1, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@112f364d, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@7103cb56, org.springframework.boot.test.web.reactor.netty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactory$DisableReactorResourceFactoryGlobalResourcesContextCustomizerCustomizer@48d5f34e, org.springframework.test.context.support.DynamicPropertiesContextCustomizer@0, org.springframework.boot.test.context.SpringBootTestAnnotation@94968258], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]
....
Caused by: org.hibernate.HibernateException: Unable to determine Dialect without JDBC metadata (please set 'jakarta.persistence.jdbc.url' for common cases or 'hibernate.dialect' when a custom Dialect implementation must be provided)
at app//org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:191)
... 54 more
구글링해보니 spring boot와 MySql 연동 오류라고 한다.
=> Spring Boot 컨테이너가 MySQL Dialect 설정을 못 찾았기 때문
Caused by:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to: Unable to determine Dialect without JDBC metadata (please set 'jakarta.persistence.jdbc.url' for common cases or 'hibernate.dialect' when a custom Dialect implementation must be provided)
이 에러는 Spring Boot가 JPA에서 JdbcEnvironment를 생성하려고 할 때 발생하는 오류로, Hibernate Dialect를 찾을 수 없기 때문에 발생합니다. 이는 JDBC URL을 제대로 설정하지 않았거나, hibernate.dialect를 명시적으로 지정하지 않아서 발생할 수 있습니다.
해결
<application.yml>
아래 구조로 jpa에서 hibernate.dialect 으로 명시적으로 설정하도록 수정한다.
spring:
...
datasource:
url: jdbc:mysql://localhost:3306/{db-schema-name}
driver-class-name: com.mysql.cj.jdbc.Driver
username: {username}
password: {password}
jpa:
show-sql : true
properties:
hibernate:
ddl-auto: update # 운영 환경에서는 'validate' 또는 'none'을 권장
dialect: org.hibernate.dialect.MySQL8Dialect # 중요 -mysql8 Dialect 설정
formay_sql : true