【问题标题】:Could Not autowire an object in Mule component无法自动装配 Mule 组件中的对象
【发布时间】:2015-04-30 19:02:00
【问题描述】:

我正在尝试在 mule 流中自动装配服务类的对象。代码是:

public class SignatureValidator implements Callable 
{
@Autowired
private TriggerHostServiceImpl triggerHostServiceImpl;

@Override
public Object onCall(MuleEventContext eventContext) throws Exception 
{
    MuleMessage message = eventContext.getMessage();

    message = fetchPropertiesAndValidateMessageSignature(message);

    return message.getPayload();
}

private MuleMessage fetchPropertiesAndValidateMessageSignature(MuleMessage message) throws GeneralSecurityException, IOException 
{
    String muleWSTriggerLabel = message.getInboundProperty("triggerLabel");
    String muleWSSignature    = message.getInboundProperty("signature");
    String muleWSExpiresOn    = message.getInboundProperty("expiresOn");
    String xmlData            = message.getInboundProperty("xmlData");
    String appHostName        = InitConfigurationLoader.getConfigSetting("applicationHostingName");

    Trigger triggerJaxbObject = (Trigger) message.getPayload();
    String applicationIdentifier = triggerJaxbObject.getApplicationIdentifier();

    TriggerMapper triggerMapper  = FetchConfigurationEntities.getTriggerMapper(applicationIdentifier, muleWSTriggerLabel);
    String reportEmail           = FetchConfigurationEntities.getReportEmail(triggerMapper);
    ImportDetails importInstance = FetchConfigurationEntities.getImport(triggerMapper);

    String importInstanceURL = importInstance.getWebserviceURL();

    message.setInvocationProperty("triggerJaxbObject", triggerJaxbObject);
    message.setInvocationProperty("importInstance", importInstance);
    message.setInvocationProperty("reportEmail", reportEmail);
    message.setInvocationProperty("appIdentifier", applicationIdentifier);
    message.setInvocationProperty("importHost", importInstanceURL.substring(importInstanceURL.lastIndexOf('/')+1, importInstanceURL.length()));

    setPayloadAfterValidation(message, muleWSTriggerLabel, xmlData, muleWSSignature, appHostName, muleWSExpiresOn);

    return message;
}

我的服务等级是:

package com.catalystone.csi.service;

import java.util.Map;
import java.util.Map.Entry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.catalystone.csi.core.cache.UpdateCacheable;
import com.catalystone.csi.dao.TriggerHostDao;
import com.catalystone.csi.model.TriggerHost;

@Service
public class TriggerHostServiceImpl implements TriggerHostService 
{
@Autowired
private TriggerHostDao triggerHostDao;

@Autowired
private UpdateCacheable updateCacheable;

/**
 * Method to save mule configurations i.e. TriggerHosts
 */
@Override
@Transactional
public boolean saveTriggerHost(TriggerHost triggerHost)
{
    if(triggerHostDao.saveTriggerHost(triggerHost))
    {
        Map<String, TriggerHost> allTriggerHosts = getAllTriggerHosts();
        allTriggerHosts.put(triggerHost.getTriggerIdentifier(), triggerHost);

        updateCacheable.updateAllTriggerHostCache(allTriggerHosts);

        return true;
    }
    else
        return false;
}

/**
 * Method to fetch all the configurations
 */
@Override
@Transactional//this annotation is used to maintain transaction
public Map<String, TriggerHost> getAllTriggerHosts() 
{
    return triggerHostDao.getAllTriggerHosts();
}


/**
 * Method to delete mule configuration for triggerHost
 * @return - true if delete configuration is successfully done
 */
@Override
@Transactional//this annotation is used to maintain transaction
public Boolean deleteConfiguration(TriggerHost triggerHost, boolean isMultipleImportOccurrence) 
{
    Boolean isDeleteSuccessful = triggerHostDao.deleteConfiguration(triggerHost, isMultipleImportOccurrence);

    //Getting all the configurations from cache
    Map<String, TriggerHost> allTriggerHosts = getAllTriggerHosts();

    //check if delete configuration successful then remove that configuration from cache
    if(isDeleteSuccessful)
    {
        for(Entry<String, TriggerHost> triggerHostEntry : allTriggerHosts.entrySet())
        {
            if(triggerHostEntry.getValue().getTriggerIdentifier().equals(triggerHost.getTriggerIdentifier()))
            {
                allTriggerHosts.remove(triggerHostEntry.getKey());
                break;
            }
        }
        //update cache 
        updateCacheable.updateAllTriggerHostCache(allTriggerHosts);
        return true;
    }

    return false;
}

@Override
@Transactional
public Boolean updateConfiguration(TriggerHost triggerHost)
{
    if(triggerHostDao.updateConfiguration(triggerHost))
    {
        Map<String, TriggerHost> allTriggerHosts = getAllTriggerHosts();
        allTriggerHosts.put(triggerHost.getTriggerIdentifier(), triggerHost);

        updateCacheable.updateAllTriggerHostCache(allTriggerHosts);

        return true;
    }

    return false;
}

@Override
@Transactional
public Boolean deleteConfiguration(String existingImportIdentifier)
{
    return triggerHostDao.deleteConfiguration(existingImportIdentifier);
}

}

当我运行此代码时,triggerHostServiceImpl 的值始终为空。如何自动接线?我也试过链接Dependency Injection is working at Mule application startup. Objects are getting null, when a request received and Failing by throwing NullExSpring3 Dependency Injection not working with mule 但它给了我很多我无法得到的例外。

【问题讨论】:

    标签: eclipse spring spring-mvc mule mule-component


    【解决方案1】:

    你必须自动装配接口而不是实现

    @Autowired
    private TriggerHostService triggerHostService;
    

    并添加triggerHostService的setter和getter

    【讨论】:

      猜你喜欢
      • 2015-07-31
      • 2018-12-03
      • 2016-08-03
      • 1970-01-01
      • 1970-01-01
      • 2013-10-18
      • 1970-01-01
      • 2012-01-27
      • 2016-10-09
      相关资源
      最近更新 更多