0

我有一个在模块中声明的数据库。我有一个核心业务逻辑模块,我需要在其中公开数据库。我将数据库定义为单例和服务。但是,我还需要从核心业务逻辑模块访问数据库。该服务的工作,但我无法从核心引用 tkn 数据库。

我的项目

我需要在fleet.mt1.core 模块中引用在模块fleet.mt1.dataserviceimpl 中定义的TKN 数据库。

想知道如何做到这一点?如果骆驼蓝图/春天有办法可以做到这一点???

车队.mt1.dataserviceimpl

    <cm:property-placeholder persistent-id="com.ge.digital.fleet.dataservice.impl"/>
    <!-- Ensure that only one instance of a class pdxDb is created -->
    <!-- Provide a global point of access to the object -->
    <bean class="com.ge.digital.fleet.dataservice.impl.db.PDXDatabase"
        id="pdxDb" scope="singleton"/>
    <bean class="com.ge.digital.fleet.dataservice.impl.db.TKNDatabase"
        id="tknDb" scope="singleton"/>
    <!-- PDX Data Service Implementation -->
    <bean
        class="com.ge.digital.fleet.dataservice.impl.PDXDataServiceImpl" id="pdxDataService">
        <property name="pdxDatabase" ref="pdxDb"/>
    </bean>
    <bean
        class="com.ge.digital.fleet.dataservice.impl.TKNDataServiceImpl" id="tknDataService">
        <property name="tknDatabase" ref="tknDb"/>
    </bean>
    <!-- PDX Data Service Registration -->
    <service depends-on="pdxDb"
        interface="com.ge.digital.fleet.dataservice.PDXDataService" ref="pdxDataService"/>
    <service depends-on="tknDb"
        interface="com.ge.digital.fleet.dataservice.TKNDataService" ref="tknDataService"/>
    <bean
        class="com.ge.digital.fleet.dataservice.impl.processor.ReplicatedDataProcessor" id="replicatedDataProcessor">
        <property name="pdxDatabase" ref="pdxDb"/>
    </bean>
    <bean
        class="com.ge.digital.fleet.dataservice.impl.filter.FTPFileFilter" id="ftpFileFilter"/>
    <!-- properties found in com.ge.digital.fleet.dataservice.impl.cfg under etc -->
    <bean
        class="com.ge.digital.fleet.dataservice.impl.route.ReplicatedDataRouteBuilder"
        depends-on="ftpFileFilter" id="replicatedDataRouteBuilder">
        <property name="transportSftp" value="${transportSftp}"/>
        <property name="transportFs" value="${transportFs}"/>
        <property name="username" value="${username}"/>
        <property name="host" value="${host}"/>
        <property name="port" value="${port}"/>
        <property name="pathSftp" value="${pathSftp}"/>
        <property name="pathFs" value="${pathFs}"/>
        <property name="password" value="${password}"/>
        <property name="moveToPath" value="${moveToPath}"/>
        <property name="fileArchive" value="${fileArchive}"/>
        <property name="readLockFile" value="${readLockFile}"/>
        <property name="ftpFileFilter" value="ftpFileFilter"/>
    </bean>
    <camelContext id="com.ge.digital.fleet.dataServiceImplCamelContext"
        trace="false" xmlns="http://camel.apache.org/schema/blueprint">
        <routeBuilder ref="replicatedDataRouteBuilder"/>
    </camelContext>
</blueprint>

车队.mt1.core

<reference id="pdxDataService" interface="com.ge.digital.fleet.dataservice.PDXDataService"/>
<bean
    class="com.ge.digital.fleet.core.processors.DbAvailableProcessor" id="dbAvailableProcessor">
    <property name="dataService" ref="pdxDataService"/>
</bean>

<reference id="tknDataService" interface="com.ge.digital.fleet.dataservice.TKNDataService"/>
<bean class="com.ge.digital.fleet.dataservice.impl.db.TKNDatabase"
        id="tknDb" scope="singleton"/>
    <bean
        class="com.ge.digital.fleet.core.processors.AccessKeyMarsheler" id="accessKeyMarsheler">
        <property name="tknDatabase" ref="tknDb"/>
    </bean>

这是错误的,我知道,这是我的问题,如何或可以在核心模块中引用它?

<bean class="com.ge.digital.fleet.dataservice.impl.db.TKNDatabase"
        id="tknDb" scope="singleton"/>

谢谢你的帮助!我正在为此苦苦挣扎。我尝试过引用 Bean、Class 但当然,这是非法的语法。

我正在为服务开发另一个接口以跨模块访问它,我想我希望有一种方法可以在 Spring 中执行此操作,作为引用或依赖项或其他东西。

4

1 回答 1

0

在等待答案以查看 Spring 是否可行时,我继续为方法和接口创建了包装器,它工作正常,但是,我很想知道这是否可以在 Spring 中通过参考或其他东西来完成。我需要在春天学习和掩体。

再次感谢。

public class TKNDataServiceImpl implements TKNDataService {

    private static final Logger LOG = LoggerFactory.getLogger(TKNDataServiceImpl.class);

    private TKNDatabase tknDb = null;

    @Override
    public boolean isTKNDataServiceAvailable() {
        return tknDb.isAvailable();
    }

    @Override
    public TknLocator getTokenLocatorForCustomerKey(String custkey) throws TKNDataServiceUnavailableException,
            TKNDataServiceInvalidDataException {

        if (null != custkey) {

            final String token = tknDb.getAccessToken(custkey);
            Timestamp expiry = tknDb.getExpiry(custkey);
            LOG.info("ACCESS TOKEN: " + token);
            LOG.info("EXPIRY: " + expiry);
            TknLocator loc = new TknLocator();
            loc.setAccess_token(token);
            loc.setexpires_in(expiry);

            return loc;
        }

        return null;
    }

    @Override
    public boolean CustomerKeyExistsInTokenDb(String custkey) throws TKNDataServiceInvalidDataException,
            TKNDataServiceUnavailableException {

        boolean keyExists = tknDb.doesCustKeyExist(custkey);
        return keyExists;
    }

    @Override
    public void TknDbAddRow(String custkey, String access_token, int expires_in) { 
        if (null != custkey) {
            tknDb.addRow(custkey, access_token, expires_in);
        }
    }

    @Override
    public void TknReplicationComplete() { 
        tknDb.replicationComplete();
    }

    @Override
    public void TknDropRow(String custkey) { 
        if (null != custkey) {
            tknDb.dropRow(custkey);
        }
    }

    public Timestamp TknGetExpiry(String custkey) throws TKNDataServiceUnavailableException, 
                TKNDataServiceInvalidDataException {

        return(tknDb.getExpiry(custkey));
    }

    public String TknGetAccessToken(String custkey) throws TKNDataServiceUnavailableException,
            TKNDataServiceInvalidDataException {

        return(tknDb.getAccessToken(custkey));
    }


    public void settknDatabase(TKNDatabase tknDb) {
        this.tknDb = tknDb;
    }

}
于 2019-07-26T22:37:42.240 回答