Micronaut-配置Oracle UCP多个数据源和jdbcOperations

问题描述 投票:0回答:1

我正在开发我的第一个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;
        });

}
oracle jdbc repository micronaut ucp
1个回答
0
投票

您能否查看此blog了解更多详细信息?

© www.soinside.com 2019 - 2024. All rights reserved.