我在运行程序时运行schema.sql时遇到问题。
在我的pom.xml中,我已经有了mysql配置:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我只有一堂课
@SpringBootApplication
public class Application {...}
Run Code Online (Sandbox Code Playgroud)
在src / resources下,我有schema.sql,其中包含:
DROP TABLE IF EXISTS test_table;
CREATE TABLE test_table (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
...
);
Run Code Online (Sandbox Code Playgroud)
在src / resources下,我有application.yml,其中包含:
spring.datasource.driverClassName: "com.mysql.jdbc.Driver"
spring.datasource.url: "jdbc:mysql://localhost:3306/sample?useSSL=false"
spring.datasource.username: "****"
spring.datasource.password: "****"
Run Code Online (Sandbox Code Playgroud)
我已经确认启动应用程序后就可以连接到数据库“示例”,但是,它没有创建表。请指教。
那是因为 Spring Boot 有签入DataSourceInitializer's initSchema()方法。
仅当您的数据库类型为 H2,DERBY,HSQL
但是,您可以通过在 application.properties 中使用以下设置来覆盖此行为
spring.datasource.initialization-mode=always
Run Code Online (Sandbox Code Playgroud)
DataSourceInitializer.java EmbeddedDatabaseConnection.java
在我的情况下(Spring Boot 2.0.0+),只有将属性设置spring.datasource.initialization-mode=always与结合使用时,它才能按预期工作 spring.jpa.hibernate.ddl-auto=none。
| 归档时间: |
|
| 查看次数: |
3031 次 |
| 最近记录: |