1

I got Spring boot with Spring batch project. Inside my BatchConfiguration I want to get command line arguments so I @Autowire Environment object and try to get my prop but I'm getting null.

After some debug I figured out that I can get all command line args via special property Name "nonOptionArgs" but in this case I got plain string of all arguments passed. Is there some better solution?

Thanks

1
  • How do you pass parameters in command line? Commented Dec 3, 2015 at 14:48

2 Answers 2

1

You are doing everything right with autowired environment. Make sure you pass arguments in the command line with "--"

From documentation:

By default SpringApplication will convert any command line option arguments (starting with ‘--’, e.g. --server.port=9000) to a property and add it to the Spring Environment. As mentioned above, command line properties always take precedence over other property sources.

Sign up to request clarification or add additional context in comments.

Comments

0

you can run your app like this:

$ java -server -Dmyproperty=blabla -jar myapp.jar

and can access the value of myproperty in code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.