Java 自动接线接口错误

Java 自动接线接口错误,java,spring,interface,spring-integration,autowired,Java,Spring,Interface,Spring Integration,Autowired,所以我有一个spring集成项目。将网关用作spring批处理作业的触发器。我为网关创建了此接口: public interface TestGateway { void trigger(String pass); } 然后是触发接口的java类: public class Trigger implements Runnable { @Autowired TestGateway testGateWay; public void triggerMethod() { test

所以我有一个spring集成项目。将网关用作spring批处理作业的触发器。我为网关创建了此接口:

public interface TestGateway {
    void trigger(String pass);
}
然后是触发接口的java类:

public class Trigger implements Runnable {

@Autowired
TestGateway testGateWay;

public void triggerMethod() {

    testGateWay.trigger("pass");
}

@Override
public void run() {
    try {
        triggerMethod();
    } catch (Exception e) {
        e.printStackTrace();
       }
    }
 }
每次我尝试运行它时,都会出现一个异常:

java.lang.NullPointerException
at com.irsis.integration.endpoint.Trigger.triggerMethod(Trigger.java:12)
at com.irsis.integration.endpoint.Trigger.run(Trigger.java:18)
at org.springframework.scheduling.support.DelegatingErrorHandling
第22行是:
testGateWay.trigger(“pass”)

my integration-context.xml

    <context:component-scan base-package="com.irsis.integration.endpoint" />

<int:logging-channel-adapter id="logger"
    log-full-message="true" level="INFO" />

<!-- gateway -->
<int:channel id="testInput" />

<int:gateway id="testGateway"
    service-interface="com.irsis.integration.endpoint.TestGateway">
    <int:method name="trigger" request-channel="testInput" />
</int:gateway>

<int:channel id="activate" />

<import resource="classpath*:/spring/batch/jobs/testJob.xml" />

<int:transformer input-channel="testInput"
    output-channel="activate">
    <bean class="com.irsis.integration.util.TriggerToJobRequest">
        <property name="job" ref="testJob" />
    </bean>
</int:transformer>



<int:service-activator method="launch"
    input-channel="activate">
    <bean id="messageHandler"
        class="org.springframework.batch.integration.launch.JobLaunchingMessageHandler">
        <constructor-arg ref="jobLauncher" />
    </bean>
</int:service-activator>
<context:annotation-config />
<context:spring-configured />

<import resource="classpath*:/spring/integration/si-batch-config.xml" />
    <import resource="classpath*:/spring/integration/si-test2.xml" />


<context:component-scan base-package="com.irsis" />

开始我的应用程序-context.xml

    <context:component-scan base-package="com.irsis.integration.endpoint" />

<int:logging-channel-adapter id="logger"
    log-full-message="true" level="INFO" />

<!-- gateway -->
<int:channel id="testInput" />

<int:gateway id="testGateway"
    service-interface="com.irsis.integration.endpoint.TestGateway">
    <int:method name="trigger" request-channel="testInput" />
</int:gateway>

<int:channel id="activate" />

<import resource="classpath*:/spring/batch/jobs/testJob.xml" />

<int:transformer input-channel="testInput"
    output-channel="activate">
    <bean class="com.irsis.integration.util.TriggerToJobRequest">
        <property name="job" ref="testJob" />
    </bean>
</int:transformer>



<int:service-activator method="launch"
    input-channel="activate">
    <bean id="messageHandler"
        class="org.springframework.batch.integration.launch.JobLaunchingMessageHandler">
        <constructor-arg ref="jobLauncher" />
    </bean>
</int:service-activator>
<context:annotation-config />
<context:spring-configured />

<import resource="classpath*:/spring/integration/si-batch-config.xml" />
    <import resource="classpath*:/spring/integration/si-test2.xml" />


<context:component-scan base-package="com.irsis" />

你知道为什么吗

谢谢,

Jet

既然您说您使用Spring集成,那么您的网关接口应该有“实现”——

大概是这样的:

<gateway id="testGateway" service-interface="com.my.proj.TestGateway" 
          default-request-channel="gatewayChannel"/>

您的代码中有一个输入错误,这可能是一个问题:

TestGateway testGateWay
试着把它改成

TestGateway testGateway

您有实现TestGateway的类吗?如果是,它有@Component注释吗?没有,我没有。因为据我所知,在spring集成中,网关接口没有实现类。我已经在我的第一个集成类上测试了一个没有实现类的接口的自动连接,它可以工作。你连接了接口,但它需要一个实现:这样看:调用时你希望spring做什么:
void trigger(String pass)我有这个“好的”。你的
触发器是Springbean吗?您的应用程序上下文看起来如何?它真的是一个完整的Spring集成上下文吗?没有足够的信息来确定为什么您的应用程序没有针对接口的Spring集成代理实现。更新了我的问题:添加了集成xml。方法name=“trigger”是我的接口“void trigger(String pass)”中的这一行'请显示您的
触发器
bean,以及如何启动应用程序上下文。我可能会猜,但似乎您没有将
集成上下文.xml
包含到整个应用程序上下文中。最后一个没有像
测试输入
激活
等bean。很好。现在您如何使用它:
新建trigger()。