Search code examples
spring-bootspring-dataspring-data-jpa

How can i make a init-sql in Spring Boot-1.4.1-RELEASE


I am developing a spring boot application:

using dependencies:

    dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:1.4.1.RELEASE")
    compile('org.springframework.boot:spring-boot-starter-data-jpa:1.4.1.RELEASE')
    compile('mysql:mysql-connector-java:5.1.39')
}

I want to run sql on init:

SET NAMES 'utf8mb4'

to support emoji read/write

I make these configs on application.properties

spring.datasource.tomcat.init-sql=SET NAMES 'utf8mb4'
spring.datasource.init-sql=SET NAMES 'utf8mb4'
spring.datasource.connection-init-sql=SET NAMES 'utf8mb4'

But i can't make it work, and there no log for this on application startup.


Solution

  • I think i found the answer, according to this answer:

    the right properties will be:

    spring.datasource.tomcat.initSQL=SET NAMES 'utf8mb4'
    

    then this will exec on connection.