我正在开发一个spring引导应用程序:
使用依赖关系:
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')
}我想在init上运行sql:
SET NAMES 'utf8mb4'支持表情符号读/写
我在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'但是我无法使它工作,并且在应用程序启动时没有日志记录。
发布于 2016-11-10 15:02:51
发布于 2016-11-10 12:59:07
请查看相关的spring 文档。
如前所述,如果脚本是mysql特定的,则需要创建一个名为schema.sql或schema-mysql.sql的文件,并将脚本放在那里。另外,确保设置了spring.jpa.hibernate.ddl-auto=none。
你可以在医生里读到细节。
发布于 2022-03-02 12:43:03
首先,您可以创建配置bean:
@Configuration
public class JdbcConfig {
@Bean
@Primary
@ConfigurationProperties("db.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
}然后添加到您的application.yaml中
db:
datasource:
driverClassName: oracle.jdbc.driver.OracleDriver
jdbcUrl:
username:
password:
initSQL: "YOUR INIT SQL HERE"https://stackoverflow.com/questions/40527477
复制相似问题