{"id":32494,"date":"2016-03-06T14:47:17","date_gmt":"2016-03-06T09:17:17","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=32494"},"modified":"2017-08-03T13:18:09","modified_gmt":"2017-08-03T07:48:09","slug":"jhipster-rad-with-spring-boot-and-angularjs","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/jhipster-rad-with-spring-boot-and-angularjs\/","title":{"rendered":"JHipster : RAD with Spring Boot and AngularJS"},"content":{"rendered":"<p>What if we want to build our new app with technology like Spring Boot exhibiting REST APIs with an <a title=\"AngularJS Development\" href=\"http:\/\/www.tothenew.com\/front-end-angularjs-development\">AngularJS front end<\/a>? This basically involves 2\u00a0steps:<\/p>\n<ol>\n<li>Setup the backend app using Spring Boot<\/li>\n<li>Setup the frontend app using AngularJS<\/li>\n<\/ol>\n<p>Setting up these 2 separate environments have their own quirks. Beside of setting up the framework we have to setup some build tools also to manage the dependencies, i.e., <strong>Bower<\/strong>, <strong>Grunt<\/strong>, <strong>Gradle<\/strong> or <strong>Maven<\/strong>. So in initial time, we would do mostly setting up the things like logging, security, database, different environments and then get the apps in working state and build on top of it.\u00a0This requires extra effort and time. The real pain is you have to synchronize between two different technologies like Spring and Angular. Without proper structure, your app and code would go wild in a matter of weeks.<\/p>\n<p>To overcome above issues, we have a new tool or may be a\u00a0framework (if you like to call it that), which binds Spring Boot and AngularJS in one. It&#8217;s\u00a0<strong>JHipster<\/strong>.<\/p>\n<p>JHipster generates a minimal Spring Boot application with <a title=\"Building Intuitive Frontend Interfaces with AngularJS\" href=\"http:\/\/www.tothenew.com\/blog\/building-intuitive-frontend-interfaces-with-angularjs\/\">AngularJS front end<\/a>, along with the build tools like<strong> Gradle<\/strong> or <b>M<\/b><strong>aven<\/strong> for Spring Boot and <strong>Bower<\/strong>, <strong>Grunt<\/strong> or <strong>Gulp<\/strong>\u00a0for AngularJS,\u00a0configured already, all working seamlessly. It provides us support to build the application for production using Gradle or Maven and minifying and building\u00a0front-end artifacts using gulp or grunt.<\/p>\n<p>Getting started with JHipster with as easy as issuing command\u00a0<strong>yo jhipster<\/strong>.\u00a0Let\u2019s see how to get it up and running.<\/p>\n<p>&nbsp;<\/p>\n<h4>Installing<\/h4>\n<ol>\n<li><a title=\"Install node\" href=\"https:\/\/nodejs.org\/en\/download\/package-manager\/\">Install\u00a0<\/a><strong><a title=\"Install node\" href=\"https:\/\/nodejs.org\/en\/download\/package-manager\/\">node<\/a>\u00a0<\/strong>which will also install\u00a0<strong>npm<\/strong><\/li>\n<li>Install yeoman, bower, grunt and gulp using\u00a0<strong>npm install -g yo bower grunt-cli gulp<\/strong><\/li>\n<li>Install JHipster using <strong>npm install -g generator-jhipster<\/strong><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4>Generating the application<\/h4>\n<ol>\n<li>Create a folder with your app&#8217;s name and change into it using <strong>mkdir myApp &amp;&amp; cd myApp<\/strong><\/li>\n<li>Run the Yeoman generator using\u00a0<strong>yo jhipster<\/strong><\/li>\n<li>Follow up with answering all the questions and you are done as shown in the following image:<\/li>\n<\/ol>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-32513\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/02\/myappjhipsternew.jpg\" alt=\"myappjhipsternew\" width=\"1102\" height=\"407\" \/><\/p>\n<p>Here I&#8217;ve selected my database to be <strong>PostgreSQL<\/strong>, <strong>Spring security<\/strong> as an authentication and authorization system, <strong>Gradle<\/strong> as the build tool for the backend, and <strong>Grunt<\/strong> as the build tool for the frontend.<\/p>\n<p>JHipster automatically installs all frontend dependencies using <strong>npm install &amp;&amp; bower install<\/strong>. To get backend dependencies you want to run <strong>.\/gradlew<\/strong>. One thing to note here is that if it detects Java 7 then it would generate Java 7 compliant code, and if it detects Java 8 then it would generate Java 8 compliant code that uses Lambdas.<\/p>\n<p>&nbsp;<\/p>\n<h4>Walkthrough<\/h4>\n<p>Let&#8217;s discover what the JHipster has done for us.<\/p>\n<ol>\n<li>\u00a0<strong>\/src\/main\/java\u00a0<\/strong>folder contains our Spring code distributed as follows:\n<ul>\n<li><strong>config<\/strong> folder contains\u00a0Spring&#8217;s configuration.<\/li>\n<li><strong>domain<\/strong> folder contains all domain classes that are mapped by Hibernate to our choice of database, in this case, PostgreSQL.<\/li>\n<li><strong>repository\u00a0<\/strong>folder contains all of the Spring Data based repositories.<\/li>\n<li><strong>service\u00a0<\/strong>folder contains all of the\u00a0<strong>@Service\u00a0<\/strong>annotated class those are transactional.<\/li>\n<li><strong>security\u00a0<\/strong>folder contains all of the Spring Security based implementations like a simple implementation of\u00a0<b>UserDetailsService<\/b>.<\/li>\n<li><strong>web.rest\u00a0<\/strong>folder contains all of the REST endpoints which uses Spring MVC&#8217;s REST support.<\/li>\n<\/ul>\n<\/li>\n<li><strong>\/src\/main\/resources\/config\/liquibase<\/strong> folder contains Liquibase changeset files. This folder also contains csv files to build initial users and authorities for the application.<\/li>\n<li><strong>\/src\/main\/webapp<\/strong> folder contains our AngularJS code described as follows:\n<ul>\n<li><strong>scripts.component\u00a0<\/strong>folder contains all of the AngularJS&#8217; artifacts, like\u00a0<strong>filters\u00a0<\/strong>and\u00a0<strong>services<\/strong>.<\/li>\n<li><strong>scripts.app<\/strong> folder contains all of the app&#8217;s JavaScript code that includes HTML and Angular Controllers distributed in the various folder like\u00a0<strong>account<\/strong>,\u00a0<strong>admin<\/strong>,\u00a0<strong>entities<\/strong> etc.<\/li>\n<li><strong>scripts.components\u00a0<\/strong>folder contains all of the app&#8217;s JavaScript code that includes Angular Services.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4>Running<\/h4>\n<p>As the JHipster sample application here uses Gradle and Grunt, we just need to run the Gradle wrapper and Grunt.<\/p>\n<ul>\n<li>Execute <strong>.\/gradlew<\/strong> Gradle wrapper executable file. It would download the correct version of Gradle and run your application by executing default task <strong>bootRun<\/strong>. This command will process JS, CSS and Images to by executing Grunt tasks right inside of <strong>build.gradle<\/strong>. You will be served with the address <strong>http:\/\/localhost:8080\/<\/strong><\/li>\n<li>In another terminal execute <strong>grunt<\/strong> and it would start to build all the JS and CSS. You will be served with the address <strong>http:\/\/localhost:3000<\/strong> that allows us to reload all of the HTML and JS changes without restarting our application.<\/li>\n<li>(Optional) To build a jar file and run that jar issue the commands;\u00a0<strong>.\/gradlew -Pprod clean bootRepackage<\/strong>. And now just execute\u00a0<strong>java -jar build\/libs\/*.war &#8211;spring.profiles.active=prod<\/strong>.<\/li>\n<\/ul>\n<h4><\/h4>\n<h4>What we get by default<\/h4>\n<p>JHipster by default provides us with 4 user accounts working seamlessly. They are:<\/p>\n<ol>\n<li><strong>system: <\/strong>It has ROLE_ADMIN and ROLE_USER access. You can not access this account.<\/li>\n<li><strong>anonymousUser:\u00a0<\/strong>This account is not usable.<\/li>\n<li><strong>admin:\u00a0<\/strong>It also has ROLE_ADMIN and ROLE_USER access. The default password for this account is\u00a0<strong>admin<\/strong>.<\/li>\n<li><strong>user:\u00a0<\/strong>It has just ROLE_USER access. The default password for this account is\u00a0<strong>user<\/strong>.<\/li>\n<\/ol>\n<p>If we login by\u00a0<strong>admin<\/strong> account then we have access to certain admin level stuff of the application. Here are some screenshots to your interest (These are taken from <a title=\"JHipster screen shots\" href=\"https:\/\/jhipster.github.io\/screenshots\/\" target=\"_blank\">JHipster official home<\/a> page, as I was feeling lazy to generate them myself):<\/p>\n<h3>Welcome Screen:<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-33085\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/03\/homescreen.png\" alt=\"homescreen\" width=\"800\" height=\"416\" \/><\/p>\n<h3>Monitoring screen:<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-33086\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/03\/monitoringscreen.png\" alt=\"monitoringscreen\" width=\"800\" height=\"729\" \/><\/p>\n<h3>\u00a0One of the generated forms:<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-33088\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/03\/generatedform.png\" alt=\"generatedform\" width=\"800\" height=\"400\" \/><\/p>\n<h3>Log management screen:<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-33089\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/03\/logmanagementscreen.png\" alt=\"logmanagementscreen\" width=\"800\" height=\"416\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Next time, we will see how can we generate custom entities and define some relationships between them to facilitate some business logic using Domains, Services, Rest Controllers and AngularJS views. Till then, have a good time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What if we want to build our new app with technology like Spring Boot exhibiting REST APIs with an AngularJS front end? This basically involves 2\u00a0steps: Setup the backend app using Spring Boot Setup the frontend app using AngularJS Setting up these 2 separate environments have their own quirks. Beside of setting up the framework [&hellip;]<\/p>\n","protected":false},"author":70,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":6},"categories":[1439,3429,446],"tags":[3955,4697],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/32494"}],"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\/70"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=32494"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/32494\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=32494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=32494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=32494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}