{"id":22132,"date":"2015-07-17T22:04:29","date_gmt":"2015-07-17T16:34:29","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=22132"},"modified":"2015-07-17T22:04:29","modified_gmt":"2015-07-17T16:34:29","slug":"quick-start-with-springboot-using-cli","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/quick-start-with-springboot-using-cli\/","title":{"rendered":"Quick start with Springboot using CLI"},"content":{"rendered":"<p>SpringBoot is one of the main projects of Spring community which takes opinionated view of production ready applications. It helps you getting up and running a production grade spring application. <\/p>\n<p>It comes with even a CLI to get you quick started with springboot. CLI stands for Command Line Interface which gives *spring* command using which the application could be run.<\/p>\n<p>This CLI allows you to create a groovy script called Spring script in Springboot documentation which could be run as a spring application using simple command <\/p>\n<p><code>spring run file_name.groovy<\/code><\/p>\n<p>A simple example of a Spring script could be as below:<br \/>\n[code lang=&#8221;groovy&#8221;]<br \/>\n@Controller<br \/>\nclass Example {<br \/>\n\t@RequestMapping(&quot;\/&quot;)<br \/>\n    @ResponseBody<br \/>\n\tpublic String helloWorld() {<br \/>\n\t\t&quot;Hello Spring boot audience!!!&quot;<br \/>\n\t}<br \/>\n}<br \/>\n[\/code]<\/p>\n<p>This script just by default imports few annotation classes(e.g. Controller,ResponseBody and RequestMApping above) and add  annotations when run with CLI. In normal spring application without a springboot CLI but with springboot would require to add the imports for these.<\/p>\n<p>Below are the annotations added itself by CLI.<br \/>\n[code lang=&#8221;groovy&#8221;]<br \/>\n@Grab(&quot;org.springframework.boot:spring-boot-web-starter:0.5.0&quot;)<br \/>\n@EnableAutoConfiguration<br \/>\n[\/code]<br \/>\n@Grab annotation is used to add a starter pom. A starter pom is nothing but a collection of jars dependencies and plugins grouped together.<br \/>\nAdded above is the web starter which provides sensible defaults for a spring web applications.<br \/>\n@EnableAutoConfiguration enables default confiurations and best tries to configure the application by looking up in added jar files. For example if you have embedded a tomcat-embed.jar then it considers that you want to use tomcat.<\/p>\n<p>More, you can create FAT jars(A fat jar is simply a jar that contains all the required jars within single jar and hence can be run independently) using command below<\/p>\n<p><code>spring jar test.jar file_name.groovy<\/code><\/p>\n<p>This will create a excutable jar which could be run using following basic java command<\/p>\n<p><code>java -jar jar_file<\/code><\/p>\n<p>Springboot CLI could be installed if using GVM by running following command:<\/p>\n<p><code>gvm install springboot<\/code><\/p>\n<p>gvm is independent of OS. Though if using MAC and using Homebrew, all you need to do to install the Spring Boot CLI is:<\/p>\n<p><code>$ brew tap pivotal\/tap<br \/>\n$ brew install springboot<\/code><br \/>\nHomebrew will install spring to \/usr\/local\/bin. <\/p>\n<p>Note:If you don\u2019t see the formula, your installation of brew might be out-of-date. Just execute <\/p>\n<p><code>brew update<\/code><\/p>\n<p>and try again.<\/p>\n<p>If you are on a Mac and using MacPorts, all you need to do to install the Spring Boot CLI is: <\/p>\n<p><code>$ sudo port install spring-boot-cli <\/code><\/p>\n<p>Least but not last, springboot CLI should not be used for production stuff and just for testing and hands on purpose.<\/p>\n<p>Finally, springboot CLI is no way required or must to run a springboot rich spring application, it is just a hands on tool.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SpringBoot is one of the main projects of Spring community which takes opinionated view of production ready applications. It helps you getting up and running a production grade spring application. It comes with even a CLI to get you quick started with springboot. CLI stands for Command Line Interface which gives *spring* command using which [&hellip;]<\/p>\n","protected":false},"author":119,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1},"categories":[1],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/22132"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=22132"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/22132\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=22132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=22132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=22132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}