java - How to access command line arguments in Spring configuration? -
i have spring boot application uses spring integration stored procedure inbound channel adapter. pass command line argument stored procedure. spring boot doc says springapplication convert command line option arguments starting ‘--’ property , add spring environment. correct way access property in int-jdbc:parameter element?
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 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>
using ${arg1}
here doesn't seem resolved. proper syntax, or need define additional property or property placeholder?
starting app, e.g. java -jar app.jar --arg1=5
throws exception of
error converting typed string value bean property 'value'; nested exception org.springframework.beans.typemismatchexception: failed convert value of type [java.lang.string] required type [java.lang.integer]; nested exception java.lang.numberformatexception: input string: "${arg1}"
i thought first had type conversion , tried with
<int-jdbc:parameter name="myarg" type="java.lang.integer" value="#{ t(java.lang.integer).parseint(arg1) }" />
but didn't work either.
you don't have spring boot stuff.
i mean auto-configuration
, includes propertyplaceholderconfigurer
, too.
that must this:
@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 terminate"); system.in.read(); ctx.close(); } }
i've checked our barrier
sample: https://github.com/spring-projects/spring-integration-samples/tree/master/basic/barrier
Comments
Post a Comment