如何解决使用r2dbc-mssql指定架构
是否可以使用r2dbc-mssql在属性文件中指定默认架构?
该连接在以下情况下可以正常工作
:spring:
r2dbc:
url: 'r2dbc:mssql://zzzzz.database.windows.net:1433/dbname'
username: 'xxxxxx'
password: 'xxxxxx'
但是我必须使用静态模式:
@Table("schemaname.foo")
public class Foo {
@Id
private Long id;
我在r2dbc-postgresql中找到了类似的东西: https://github.com/pgjdbc/r2dbc-postgresql/issues/37
解决方法
在Spring Boot应用程序中,我认为您可以执行sql语句来切换@PostConstruct
类的@Configuration
方法中的模式。
@Configuration
class DatabaseConfig{
@Autowired
ConnectionFactory connectionFactory;
@PostConstruct
void init(){
Mono.from(connectionFactory.getConnection())
.flatMap(c->c.createStatement("switch to your schema here,different database has different commands here").execute())
.subscribe()
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。