Service Activatorで例外送出するとどうなるのか?
下記のsaServiceで例外を発生させる。
◆integration-graph
◆ファイル構成
ソースコードのvalはlombokを使用。
◆Main.java
public class Main {
public static void main(String[] args) {
try (val ctx = new ClassPathXmlApplicationContext("SpringIntegration.xml")) {
val inCh = ctx.getBean("inCh", MessageChannel.class);
val outCh = ctx.getBean("outCh", PollableChannel.class);
inCh.send(MessageBuilder.withPayload("test").build());
System.out.println(outCh.receive());
System.in.read();
} catch (Exception e) {
e.printStackTrace();
}
}
}
◆SampleService
@Component
public class SampleService {
@ServiceActivator
public String Exec(String msg) throws IllegalArgumentException {
throw new IllegalArgumentException("err");
}
}
◆SpringIntegration.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.1.xsd">
<context:component-scan base-package="sample.springint.exception" />
<int:channel id="inCh" />
<int:channel id="outCh">
<int:queue capacity="10" />
</int:channel>
<int:service-activator id="saService"
input-channel="inCh" output-channel="outCh" ref="sampleService" />
</beans>
◆log4j.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'> <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender"> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%p] %m%n" /> </layout> </appender> <root> <priority value="info" /> <appender-ref ref="STDOUT" /> </root> </log4j:configuration>
◆実行結果
2017-07-26 01:43:34 [INFO] Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@2e18f2: startup date [Wed Jul 26 01:43:34 JST 2017]; root of context hierarchy
2017-07-26 01:43:34 [INFO] Loading XML bean definitions from class path resource [SpringIntegration.xml]
2017-07-26 01:43:35 [INFO] Loading properties file from URL [jar:file:/C:/Users/root/.m2/repository/org/springframework/integration/spring-integration-core/4.1.4.RELEASE/spring-integration-core-4.1.4.RELEASE.jar!/META-INF/spring.integration.default.properties]
2017-07-26 01:43:35 [INFO] No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
2017-07-26 01:43:35 [INFO] No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
2017-07-26 01:43:35 [INFO] No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.
2017-07-26 01:43:35 [INFO] JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2017-07-26 01:43:35 [INFO] Loading properties file from URL [jar:file:/C:/Users/root/.m2/repository/org/springframework/integration/spring-integration-core/4.1.4.RELEASE/spring-integration-core-4.1.4.RELEASE.jar!/META-INF/spring.integration.default.properties]
2017-07-26 01:43:35 [INFO] Initializing ExecutorService 'defaultSockJsTaskScheduler'
2017-07-26 01:43:35 [INFO] Initializing ExecutorService 'taskScheduler'
2017-07-26 01:43:36 [WARN] Neither 'urlMap' nor 'mappings' set on SimpleUrlHandlerMapping
2017-07-26 01:43:36 [INFO] Starting beans in phase -2147483648
2017-07-26 01:43:36 [INFO] Starting beans in phase 0
2017-07-26 01:43:36 [INFO] Adding {service-activator:saService} as a subscriber to the 'inCh' channel
2017-07-26 01:43:36 [INFO] Channel 'org.springframework.context.support.ClassPathXmlApplicationContext@2e18f2.inCh' has 1 subscriber(s).
2017-07-26 01:43:36 [INFO] started saService
2017-07-26 01:43:36 [INFO] Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2017-07-26 01:43:36 [INFO] Channel 'org.springframework.context.support.ClassPathXmlApplicationContext@2e18f2.errorChannel' has 1 subscriber(s).
2017-07-26 01:43:36 [INFO] started _org.springframework.integration.errorLogger
こんにちは。
返信削除バグはどこに入り込むか分かりませんからね。