SpringIntegrationストアドプロシージャインバウンドチャネルアダプターを使用するSpringBootアプリケーションがあります。コマンドライン引数をストアドプロシージャに渡したいのですが。Spring Bootのドキュメントによると、SpringApplicationは、「-」で始まるコマンドラインオプション引数をプロパティに変換し、Spring環境に追加します。int-jdbc:parameter要素でこのプロパティにアクセスする正しい方法は何ですか?
Application.java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
@SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
ConfigurableApplicationContext ctx = new SpringApplication("integration.xml").run(args);
System.out.println("Hit Enter to terminate");
System.in.read();
ctx.close();
}
}
Integration.xml
<int-jdbc:stored-proc-inbound-channel-adapter
stored-procedure-name="sp_get_some_records"
data-source="dataSource"
channel="recs.in.channel"
id="recs.in">
<int:poller fixed-rate="86400" time-unit="SECONDS" />
<int-jdbc:parameter name="myarg" type="java.lang.Integer" value="${arg1}" />
</int-jdbc:stored-proc-inbound-channel-adapter>
${arg1}
ここでの使用は解決されていないようです。適切な構文は何ですか、または追加のプロパティまたはプロパティプレースホルダーを定義する必要がありますか?
アプリを起動します。たとえばjava -jar app.jar --arg1=5
、次の例外をスローします
Error converting typed String value for bean property 'value'; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert value of type [java.lang.String] to required type [java.lang.Integer]; nested exception is java.lang.NumberFormatException: For input string: "${arg1}"
私は最初にそれが型変換に関係していると思い、
<int-jdbc:parameter name="myarg" type="java.lang.Integer" value="#{ T(java.lang.Integer).parseInt(arg1) }" />
しかし、それもうまくいきませんでした。
SpringBootのものはありません。
私は意味auto-configuration
が含まれ、PropertyPlaceholderConfigurer
あまりにも、。
それは次のようなものでなければなりません:
@SpringBootApplication
@ImportResource("integration.xml")
public class Application {
public static void main(String[] args) throws Exception {
ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);
System.out.println("Hit Enter to terminate");
System.in.read();
ctx.close();
}
}
barrier
サンプルを確認しました:https://github.com/spring-projects/spring-integration-samples/tree/master/basic/barrier
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加