Micronaut-data: Текущее соединение JDBC не найдено. Подумайте о переносе этого вызова в границы транзакций
У меня нет текущего соединения JDBC. исключение при использовании данных micronaut, я имею в виду 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
DatasourceConfiguration.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;
}
}
1 ответ
Проблема решается добавлением micronaut-data-processor в annotationProcessorPaths maven-compiler-plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>${jdk.version}</release>
<encoding>UTF-8</encoding>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-inject-java</artifactId>
<version>${micronaut.version}</version>
</path>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-validation</artifactId>
<version>${micronaut.version}</version>
</path>
<path>
<groupId>io.micronaut.configuration</groupId>
<artifactId>micronaut-openapi</artifactId>
<version>${micronaut.openapi.version}</version>
</path>
<path>
<groupId>io.micronaut.data</groupId>
<artifactId>micronaut-data-processor</artifactId>
<version>1.0.2</version>
</path>
</annotationProcessorPaths>
</configuration>
<executions>
<execution>
<id>test-compile</id>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-inject-java</artifactId>
<version>${micronaut.version}</version>
</path>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-validation</artifactId>
<version>${micronaut.version}</version>
</path>
<path>
<groupId>io.micronaut.configuration</groupId>
<artifactId>micronaut-openapi</artifactId>
<version>${micronaut.openapi.version}</version>
</path>
<path>
<groupId>io.micronaut.data</groupId>
<artifactId>micronaut-data-processor</artifactId>
<version>1.0.2</version>
</path>
</annotationProcessorPaths>
</configuration>
</execution>
</executions>
</plugin>
</plugins>