I have to convert a large Spring boot application into a flexible CLI tool, where the requests sent by the Spring boot application (among other things) are determined by user input at the command line. I decided to use picocli to implement the command line functionality, however I can't figure out how to even do something as simple as print some text to stdout if the user passes a given option flag, Spring boot just runs as it normally does. How am I supposed to write this so picocli can function alongside Spring boot (and eventually control all the Spring boot stuff)
Getting Picocli to work with Springboot application
4.3k Views Asked by Guilty At
2
There are 2 best solutions below
0
Galen Howlett
On
Spring Boot is supported by PicoCLI and they even have an example to follow: https://picocli.info/#_spring_boot_example
Related Questions in JAVA
- Add image to JCheckBoxMenuItem
- How to access invisible Unordered List element with Selenium WebDriver using Java
- Inheritance in Java, apparent type vs actual type
- Java catch the ball Game
- Access objects variable & method by name
- GridBagLayout is displaying JTextField and JTextArea as short, vertical lines
- Perform a task each interval
- Compound classes stored in an array are not accessible in selenium java
- How to avoid concurrent access to a resource?
- Why does processing goes slower on implementing try catch block in java?
- Redirect inside java interceptor
- Push toolbar content below statusbar
- Animation in Java on top of JPanel
- JPA - How to query with a LIKE operator in combination with an AttributeConverter
- Java Assign a Value to an array cell
Related Questions in SPRING
- Redirect inside java interceptor
- Spring RestTemplate passing the type of the response
- spring-integration-dsl-groovy-http return null when i use httpGet method
- Custom Spring annotation for request parameters
- Spring - configure Jboss Intros for xml with java config?
- HTTP Status 404 - Not Found in Spring 3.2.7
- AndroidAnnotations how to use setBearerAuth
- android I/O error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found
- Show login dialog when not authenticated yet
- Spring Data Rest supporting json and xml
- @Value annotation not resolved in a class that belongs to dependency jar
- Remove nested _embedded fields while using projections
- How to send Rest GET request that contains "#" value in url parameters?
- How to inject spring bean into Validator(hibernate)
- How to keep a variable in the URL when using Spring LocaleChangeInterceptor
Related Questions in SPRING-BOOT
- Timing Issue with Spring Boot Annotation Configuration
- LightAdmin - Customise parsing DateTime with app timezone
- Creating distribution with repackaged spring boot jar using gradle application plugin
- Spring Boot MVC non-role based security
- Add JVM args to spring boot application
- The method and() is undefined for the type HttpSecurity
- swagger ui not working for swagger version 2
- Spring IO Platform 2.0 - Themes/Changes?
- JPA findDistinctPropertyBy magic method doesn't work as expected when using spring-boot-starter-jpa
- Spring boot check external service status on boot
- Running a specific spring batch job amongst several jobs contained withing a spring boot fat jar
- Adding security to rest api service built with Spring Boot app
- Spring Redirecting from Http to Https Breaks Rest Controller Test
- Service not starting using Spring-boot during integration tests
- Spring Boot Actuator Health Returning DOWN
Related Questions in MAVEN
- Auto reload with play2
- maven pom.xml dependencies order vs classpath/build path order
- How to ignore or fix the duplicate classes warning?
- Scala Eclipse IDE compiler giving errors until "clean" is run
- How to run multiple "mvn test"-commands from batch file?
- Not able to send email in java using SMTP,its blocked by firewall in my office.Is there any other method by which we can send mail?
- javaCV Maven project
- Logging error when executing Maven SonarQube plugin
- Gradle: Override transitive dependency by version classifier
- Why we need maven if there's javac that compiles the code?
- jar file input == null while java app is working
- JPA and web app
- Test Selector Plugin Jenkins returns No tests were executed
- Eclipse OSGI unsatisfied constraint
- GlassFish 4.0 CDI deployment failure + Apache Spark
Related Questions in PICOCLI
- Set up picocli Annotation Processor in Intellij maven project with modules
- How to configure lightbend/typesafeConfig via command line parameter when using picocli
- "Missing Required Options" warning message not displayed for missing options
- Attribute 'requiredOptionMarker' should have type 'java.lang.Character'; but found type 'java.lang.String'
- How to print picocli usage before every execution
- Circular initialization dependency with picocli, typesafe config and Guice
- Generate docs with picocli when using Guice and lombok
- How to load external application.yml into the app developed with Micronaut Picocli?
- How do I specify default subcommand?
- picocli CLI parser: hide the Java variable name while rendering the output
- How can I construct the help functionality to divide subcommands into groups with separate descriptive headers?
- Can I define custom descriptions for Mixins for separate uses with picocli?
- Possible side effects when several CommandLine instance "work" on the same instance of an annotated class?
- Graal native-image command returns error "Please specify class containing the main entry point method"
- How to read value from properties using picocli and using it connect postgres
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
As a follow-up to this I eventually got the code working by refactoring out the "controller methods" into 3 as follows:
|
|_
MainApp.java|_
CmdRunner.java|_
TheCommand.javaWhere MainApp is the
@SpringBootApplicationwhich basically just does:Kicking everything off.
CmdRunner is an
@Component& simple implementation of theCommandLineRunnerInterface provided by SpringBoot, the most important bit is below:It executes the passed cli arguments (which were passed to it from MainApp.java) on a new picocli
CommandLineobject. Which brings us to the final class,TheCommand.javawhich is simultaneously a picocli@Command& Springboot@Controllerimplementing theRunnableinterface. And essentially just contains all the logic and (ever-growing)functionality I needed to deliver.The only downside of this implementation is that when a user runs it with the
--helpflag, the app still runs the spring boot stuff making it a little unresponsive in that particular scenario.