我得到没有找到当前的 JDBC 连接。使用 micronaut-data 时出现异常,我指的是https://github.com/tdisanti/micronaut-single-ucp
微航版本
<micronaut.version>2.0.0</micronaut.version>
<micronaut.data.version>1.1.1</micronaut.data.version>
日志:
2020-07-02 19:03:30.716 [nioEventLoopGroup-1-3] ERROR i.m.h.s.netty.RoutingInBoundHandler:1839- Unexpected error occurred: No current JDBC Connection found. Consider wrapping this call in transactional boundaries.
io.micronaut.transaction.jdbc.exceptions.CannotGetJdbcConnectionException: No current JDBC Connection found. Consider wrapping this call in transactional boundaries.
at io.micronaut.transaction.jdbc.DataSourceUtils.doGetConnection(DataSourceUtils.java:135)
at io.micronaut.transaction.jdbc.DataSourceUtils.getConnection(DataSourceUtils.java:93)
at io.micronaut.transaction.jdbc.DataSourceTransactionManager.getConnection(DataSourceTransactionManager.java:342)
at io.micronaut.transaction.jdbc.DataSourceTransactionManager.getConnection(DataSourceTransactionManager.java:88)
at io.micronaut.data.jdbc.operations.DefaultJdbcRepositoryOperations.prepareStatement(DefaultJdbcRepositoryOperations.java:1185)
爪哇
@JdbcRepository(dialect = Dialect.ORACLE)
public class BooksDao {
private final JdbcOperations jdbcOperations;
@Inject
public BooksDao (JdbcOperations jdbcOperations) {
this.jdbcOperations = jdbcOperations;
}
@Transactional
public List<Book> get(){
...
}
}
yml 属性
datasources:
default:
validationQuery: SELECT 1 FROM DUAL
driverClass: oracle.jdbc.driver.OracleDriver
url: jdbc:oracle:thin:<url>,cn=OracleContext,dc=uk,dc=csfb,dc=com
autoCommit: true
connectionTestQuery: SELECT 1 FROM DUAL
leakDetectionThreshold: 180000
poolName: hikariConnectionPoolName
maximumPoolSize: 10
minimumIdle: 5
data-source-properties:
truststore: '${client.truststore.path}'
truststore.password: '${client.truststore.password}'
truststore.type: JKS
keystore: '${client.keystore.path}'
keystore.password: '${client.keystore.password}'
keystore.type: PKCS12
dialect: ORACLE
数据源配置.java
@Singleton
public class DatasourceConfiguration implements BeanCreatedEventListener<DatasourceConfiguration> {
@Override
public DatasourceConfiguration onCreated(BeanCreatedEvent<DatasourceConfiguration> event) {
LOGGER.info("Overriding DatasourceConfiguration Properties...");
DatasourceConfiguration bean = event.getBean();
Properties dataSourceProperties = bean.getDataSourceProperties();
Map<String, String> props = new HashMap<>();
props.put("javax.net.ssl.keyStore",dataSourceProperties.getProperty("keystore"));
props.put("javax.net.ssl.keyStorePassword",dataSourceProperties.getProperty("keystore.password"));
props.put("javax.net.ssl.keyStoreType",dataSourceProperties.getProperty("keystore.type"));
props.put("javax.net.ssl.trustStore",dataSourceProperties.getProperty("truststore"));
props.put("javax.net.ssl.trustStorePassword",dataSourceProperties.getProperty("truststore.password"));
props.put("javax.net.ssl.trustStoreType",dataSourceProperties.getProperty("truststore.type"));
props.put("oracle.net.authentication_services","(TCPS)");
props.put("oracle.net.ssl_client_authentication","TRUE");
props.put("ssl.keyManagerFactory.algorithm","SunX509");
props.put("oracle.net.ssl_cipher_suites","(TLS_RSA_WITH_AES_256_CBC_SHA)");
props.put("oracle.net.encryption_client","REJECTED");
props.put("oracle.net.crypto_checksum_client","REJECTED");
bean.setDataSourceProperties(props);
return bean;
}
}