我正在尝试使用 H2 数据库创建一个 Spring Boot 项目,其他程序可以访问该项目。
应用程序属性
spring.datasource.url = jdbc:h2:tcp://localhost:8084/~/./db/tech
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.datasource.initialization-mode=always
Run Code Online (Sandbox Code Playgroud)
SpringBootMyApplication.java
@SpringBootApplication
public class SpringBootMyApplication{
public static void main(String[] args) {
SpringApplication.run(SpringBootMyApplication.class, args);
}
@Bean(initMethod = "start", destroyMethod = "stop")
public Server h2Server() throws SQLException {
return Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", "8084");
}
}
Run Code Online (Sandbox Code Playgroud)
例外是:
Caused by: org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database "C:/Users/onz03589/db/tech" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200]
Run Code Online (Sandbox Code Playgroud)
如何真正“允许创建远程数据库”?
您需要添加"-ifNotExists"参数到Server.createTcpServer(). "-tcpAllowOthers"但是,再次强调,除非您的端口受到某种保护,否则您不应该将其与 一起使用。
| 归档时间: |
|
| 查看次数: |
2878 次 |
| 最近记录: |