从项目中的不同模块引用一个 bean?

reference a bean from different modules in a project?

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

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

想知道如何做到这一点?如果骆驼蓝图/spring中有方法可以做到这一点???

舰队。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 中有一种方法可以做到这一点,作为参考或依赖项或其他东西。

在等待答案以查看 Spring 是否可行时,我继续为方法和接口创建了包装器,它工作正常,但是,我很想知道这是否可以完成在 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;
    }

}