简体   繁体   English

Spring Boot 2.x连接工厂

[英]Spring Boot 2.x Connection Factory

I have the below class that works well in Spring Boot 1.5.x 我有下面的类在Spring Boot 1.5.x中运行良好

public ConnectionFactory connectionFactory() {
        org.springframework.data.jdbc.config.oracle.AqJmsFactoryBeanFactory f=new AqJmsFactoryBeanFactory();
        f.setDataSource(dataSource);
        f.setCoordinateWithDataSourceTransactions(true);
        f.setNativeJdbcExtractor(new org.springframework.jdbc.support.nativejdbc.Jdbc4NativeJdbcExtractor());
        f.setConnectionFactoryType(ConnectionFactoryType.QUEUE_CONNECTION);
        try {
            return f.getObject();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

I have now upgraded to 2.0.4 version where NativeJdbcExtractor is not present. 我现在已升级到不存在NativeJdbcExtractor的2.0.4版本。 Can someone help me how to reconfgure the above to get the connectionFactory. 有人可以帮我如何重新配置​​上面的内容以获得connectionFactory。

The whole nativejdbc hierarchy doesn't exists anymore and what isn't there anymore cannot be used.So either don't upgrade or figure out a way to not need it (jdbc 4 can use unwrap to get the actual underlying connection). 整个nativejdbc层次结构已不存在,因此不再可用,因此不要升级或找出不需要它的方法(jdbc 4可以使用unwrap来获取实际的基础连接)。

To get the actual underlying connection there is an unwrap method on the Connection. 为了获得实际的基础连接,在Connection上有一个unwrap方法。 So something along the lines of connection.unwrap(OracleConnection.class) should get you the actual underlying connection. 因此,与connection.unwrap(OracleConnection.class)类似的东西应该可以为您提供实际的基础连接。 However that might require an additional upgrade of the aq-jms-connection-factory which I'm not certain supports Spring 5.0. 但是,这可能需要对aq-jms-connection-factory进行额外的升级,我不确定它是否支持Spring 5.0。

I have used something like this which can help you : 我已经使用过类似的方法,可以为您提供帮助:

public OracleConnection getOracleConnection(Connection connection) throws SQLException {
    OracleConnection oconn = null;
    try {
        if (connection.isWrapperFor(oracle.jdbc.OracleConnection.class)) {
            oconn = (OracleConnection) connection.unwrap(oracle.jdbc.OracleConnection.class)._getPC();
        }
    } catch (SQLException e) {
        throw e;
    }
    return oconn;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM