所以我有这个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");
我的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>
启动我的application-context.xml
<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" />
任何想法为什么?
谢谢,
喷射
答案 0 :(得分:0)
由于您说您使用的是Spring Integration,因此您的网关接口应该具有“实施”功能。 - <gateway>
这样的事情:
<gateway id="testGateway" service-interface="com.my.proj.TestGateway"
default-request-channel="gatewayChannel"/>
答案 1 :(得分:0)
您的代码中存在拼写错误,这可能是个问题:
TestGateway testGateWay
尝试将其更改为
TestGateway testGateway