我正在开发我的第一个micronaut应用程序,但在使用ucp配置oracle多个数据源时遇到问题。
我尝试执行选择时遵循官方教程(https://micronaut-projects.github.io/micronaut-sql/latest/guide/),但出现错误:
io.micronaut.transaction.jdbc.exceptions.CannotGetJdbcConnectionException: No current JDBC Connection found. Consider wrapping this call in transactional boundaries.
我检查DataSourceFactory并正确设置PoolDataSource
我想念什么?
谢谢!
micronaut:
application:
name: myapp
datasources:
first:
url: url
connectionFactoryClassName: oracle.jdbc.pool.OracleDataSource
username: user
password: password
minPoolSize: 1
maxPoolSize: 10
second:
url: url
connectionFactoryClassName: oracle.jdbc.pool.OracleDataSource
username: user
password: password
minPoolSize: 1
maxPoolSize: 10
@JdbcRepository(dialect = Dialect.ORACLE)
public abstract class MyRepository {
@Inject
@Named("first")
protected final DataSource dataSource;
protected final JdbcOperations jdbcOperations;
public MyRepository(JdbcOperations jdbcOperations, DataSource dataSource) {
this.dataSource = dataSource;
this.jdbcOperations = jdbcOperations;
}
}
@Singleton
public class MyDao extends MyRepository {
public MyDao(JdbcOperations jdbcOperations, DataSource dataSource) {
super(jdbcOperations, dataSource);
}
@Transactional
public Long find() {
String sql = "select * from table where id = 1";
return this.jdbcOperations.prepareStatement(sql, st -> {
return 1L;
});
}
您能否查看此blog了解更多详细信息?