발생한 오류

org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Wrong user name or password [28000-200

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]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:275)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:176)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:127)

*위에 있는 오류처럼 오류가 발생했을 경우*

1. H2 데이터 베이스가 켜져 있는지 확인을 합니다.

2. 안 켜져 있으면 H2 데이터 베이스를 켜줍니다.

3. 키고 밑에 있는 사진의 내용들을 보고 application.properties 또는 application.yml를 확인합니다.

*application.properties

 

*application.yml

 

이렇게 작성되어 있다면 spring.datasource.username=sa를 추가해주면 오류가 해결됩니다.

저걸 추가해주기 전에  build.gradle에 들어가서 스프링 부트 버전을 확인합니다.

이유는 스프링 부트 버전이 2.4부터는 username을 작성해줘야 합니다.

그러므로 저런 오류가 발생하면 build.gradle에 들어가서  버전을 확인해보시기 바랍니다.

 

*application.yml

spring:
    datasource:
        url: jdbc:h2:tcp://localhost/~/test
        driver-class-name: org.h2.Driver
        username: sa
    jpa:
        hibernate:
            ddl-auto: none
       show-sql: true

*application.properties

spring.datasource.url=jdbc:h2:tcp://localhost/~/test
spring.datasource.driver-class-name=org.h2.Driver
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=none
spring.datasource.username=sa