How to access command line arguments in Spring configuration?

broetchen

I have a Spring Boot application that uses a Spring Integration Stored Procedure Inbound Channel Adapter. I would like to pass a command line argument to the stored procedure. The Spring Boot doc says that SpringApplication will convert any command line option arguments starting with ‘--’ to a property and add it to the Spring Environment. What is the correct way to access this property in the 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 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>

Using ${arg1} here doesn't seem to get resolved. What is the proper syntax, or do I need to define an additional property or property placeholder?

Starting the app, e.g. with java -jar app.jar --arg1=5 throws an exception of

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}"

I thought first it had to do with type conversion and tried with

<int-jdbc:parameter name="myarg" type="java.lang.Integer" value="#{ T(java.lang.Integer).parseInt(arg1) }" />

but that didn't work either.

Artem Bilan

You don't have any Spring Boot stuff.

I mean auto-configuration, which includes PropertyPlaceholderConfigurer, too.

That must be something like 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 to terminate");
        System.in.read();
        ctx.close();
    }    
}

I've just checked with our barrier sample: https://github.com/spring-projects/spring-integration-samples/tree/master/basic/barrier

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to access command line arguments in .csx script?

From Dev

How to get command Line arguments in spring boot?

From Dev

Access command line arguments in Julia

From Dev

Access command line arguments in Julia

From Java

How do you access command line arguments in Swift?

From Dev

How do I access command line arguments in SICStus Prolog?

From Dev

Flask configuration handling via command line arguments?

From Dev

How to Retrieve Command Line Arguments

From Dev

Access to command line user arguments using getopt

From Dev

How to access command line arguments in a node.js child process using child_process.exec?

From Dev

How to send in command line arguments for a python file execution in command line?

From Dev

How to give python command line arguments from command line mode

From Dev

How to properly compare command-line arguments?

From Dev

How to pass command line arguments in kubernetes?

From Java

How to pass command line arguments to a rake task

From Java

How to read/process command line arguments?

From Java

How to handle command-line arguments in PowerShell

From Dev

How to pass command line arguments to a c program

From Dev

How to add PhantomJSDriver command line arguments

From Dev

How to pass command line arguments to ipython

From Dev

How to store command line arguments for future use?

From Dev

How to modify the command line arguments before getopt()

From Dev

How to create a task that prints command line arguments?

From Dev

How to parse command line arguments with flags and without

From Dev

How to get command line arguments in Ceylon?

From Dev

How to pass array of arguments to cURL in command line?

From Dev

How to handle no command-line arguments in D?

From Dev

How to pass command line arguments to Junit Test

From Dev

How to group command-line arguments in python?

Related Related

  1. 1

    How to access command line arguments in .csx script?

  2. 2

    How to get command Line arguments in spring boot?

  3. 3

    Access command line arguments in Julia

  4. 4

    Access command line arguments in Julia

  5. 5

    How do you access command line arguments in Swift?

  6. 6

    How do I access command line arguments in SICStus Prolog?

  7. 7

    Flask configuration handling via command line arguments?

  8. 8

    How to Retrieve Command Line Arguments

  9. 9

    Access to command line user arguments using getopt

  10. 10

    How to access command line arguments in a node.js child process using child_process.exec?

  11. 11

    How to send in command line arguments for a python file execution in command line?

  12. 12

    How to give python command line arguments from command line mode

  13. 13

    How to properly compare command-line arguments?

  14. 14

    How to pass command line arguments in kubernetes?

  15. 15

    How to pass command line arguments to a rake task

  16. 16

    How to read/process command line arguments?

  17. 17

    How to handle command-line arguments in PowerShell

  18. 18

    How to pass command line arguments to a c program

  19. 19

    How to add PhantomJSDriver command line arguments

  20. 20

    How to pass command line arguments to ipython

  21. 21

    How to store command line arguments for future use?

  22. 22

    How to modify the command line arguments before getopt()

  23. 23

    How to create a task that prints command line arguments?

  24. 24

    How to parse command line arguments with flags and without

  25. 25

    How to get command line arguments in Ceylon?

  26. 26

    How to pass array of arguments to cURL in command line?

  27. 27

    How to handle no command-line arguments in D?

  28. 28

    How to pass command line arguments to Junit Test

  29. 29

    How to group command-line arguments in python?

HotTag

Archive