2

我得到没有找到当前的 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;
    }
}
4

1 回答 1

2

通过在 maven-compiler-plugin 的 annotationProcessorPaths 中添加 micronaut-data-processor 解决了该问题。

 <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>
于 2020-07-02T15:29:36.603 回答