通过蓝图XML设置参考



我试图将接口作为类中的属性(继承另一个类)中的属性传递,我遇到了一个错误。我在一堂课中尝试了同一件事,该课程没有继承任何东西,而且效果很好。我不知道我在这里是否缺少任何东西。任何帮助都将受到赞赏。谢谢:)

类:

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.impl.ScheduledPollConsumer;
import com.walmart.utils.storeConfig.api.IStoreConfigService;

public class WalPipeConsumer extends ScheduledPollConsumer
{
    final static private String CLASS_NAME = WalPipeConsumer.class.getName();
    final static private Logger logger = Logger.getLogger(CLASS_NAME);
    protected Hashtable pipeBuffers;
    private Vector msgs = new Vector();
    private int arrrayLength = 0, headerLength = 0;
    private final Endpoint endpoint;
    private final String pipe;
    private IStoreConfigService storeConfigService;
public WalPipeConsumer(Endpoint endpoint, Processor processor, String pipe)
        throws Exception
{
    super(endpoint, processor);
    logger.finest("inside the wal pipe consumer constructor");
    this.pipe = pipe;
    this.endpoint = endpoint;
    this.countryCode = countryCode;
    logger.finest("before starting the thread");
    new Thread(new WalPipeInputRunner(), "WalCamel Pipe Consumer[" + pipe
            + "]").start();
    logger.finest("after starting the thread");
}
// There are some more functions 
/**
 * @param storeConfigServicethe storeConfigService to set
 */
public void setStoreConfigService(IStoreConfigService storeConfigService) {
    this.storeConfigService = storeConfigService;
}

blueprint.xml:

<reference id="storeConfigService"
    interface="com.walmart.utils.storeConfig.api.IStoreConfigService" />
<bean id="storeConfigAdapter" class="com.tgcs.walpipe.endpoint.StoreConfigAdapter" init-method="init">
    <property name="storeConfigService" ref="storeConfigService" />
</bean>
<bean id="WalPipeConsumer" class="com.tgcs.walpipe.endpoint.WalPipeConsumer">
    <property name="storeConfigService" ref="storeConfigService" /> 
</bean>

错误:

[2017.09.15-10:34:00.788] [SEVERE] 
[org.apache.aries.blueprint.container.BlueprintContainerImpl] 
[org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun] - Unable 
to start blueprint container for bundle com.tgcs.walpipe.endpoint
org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to 
find a matching constructor on class 
com.tgcs.walpipe.endpoint.WalPipeConsumer for arguments [] when 
instanciating bean WalPipeConsumer 

蓝图试图创建一个walpipececumer的实例。您正在使用属性来设置StoreconFigService。因此,BluePrint将首先调用空构造函数以实例化类,然后致电设置器设置StoreconFigService。

由于类没有空约束,因此会失败。

要解决这个问题,您要么需要一个空构造函数,要么使用元素来设置现有构造函数的所有参数。

最新更新