Skip to main content

Posts

Showing posts from July, 2015

Spring Boot Reading Properties File

Points To Remember You can use  @PropertySource  annotation to load the properties file from classpath. Keep your properties file under the resources folder. Use  @Value  annotation to load the values from property file with "${key}"  as key. Load Properties file from classpath in Spring boot. Your properties file look like following. spring.data1=sampleData1 spring.data2=sampleData2 spring.data3=sampleData3 You can load the properties using the following two approaches In this approach you can specify a prefix with which your config starts in the properties file @Component @PropertySource("sample.properties") @ConfigurationProperties(prefix = "spring") public class SampleConfig { private String data1; private String data2; private String data3; // GETTERS and SETTERS } In this approach you need to specify the whole key to read the value from the properties file. @Component @PropertySource(value = "sample.properties") public c

Angularjs RouteParams with ngRoute

Points To Remember You should pass the params separated by "/" . You can pass the params to the controller and pass them to the templates or apply logic. You need to add $routeParams input to your controller function to get these params. How to pass Params from one state to another in AngularJs using ngRoute. You need to add the route params along with the url e.g you can send the params as follows #url/param1/param2 This is how you can update your $routeProvider to use these route params. Finally, access the params in the controller and pass them to the template. Putting everything together the code will work as shown in the plunk below.

Get Current Environment in Grails

How to create custom Environments in GRAILS. This is how you can specify the environments in your grails application. Below we have made five environments. production uat (custom) qa (custom) development test environments { production { grails.serverURL = "http://www.ekiras.com/" } uat { grails.serverURL = "http://uat.ekiras.com:8080/" } qa { grails.serverURL = "http://qa.ekiras.com:8080/" } development { grails.serverURL = "http://localhost:8080/${appName}" } test { grails.serverURL = "http://localhost:8080/${appName}" } } There are Five predefined environments in grails. APPLICATION CUSTOM DEVELOPMENT PRODUCTION TEST How to get Execute a particular Environment in GRAILS To run a particular environment in grails you can do the following grails -Denv=qa -Dserver.port=8080 run-app How to get Current Environment in Grails Controller You can get current environ

Spring MVC handle Exceptions in Controller using @ExceptionHandler

Points To Remember You can handle all types of runtime exceptions and custom exceptions using  @ExceptionHandler  annotation.  You just need to define the class to the annotation to handle exceptions of that class. Spring MVC handle Exceptions in Controller Here we have a simple Spring MVC application with the following. HomeController wih three actions  throw1 - throws Custom exception throw2 - throws Custom exception throw3 - throws Runtime exception Home Controller package com.ekiras.controller; import java.text.DateFormat; import java.util.Date; import java.util.Locale; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import com.ekiras.exc

Send JSON object as data in Ajax POST/ GET call

Send JSON object as data in Ajax call. Suppose you have  a JSON object associated with a variable say json  in our case, you can send this json value as data in the ajax call as follows. var json = [{'id':1,'name':'user1'},{'id':2,'name':'user2'},{'id':3,'name':'user3'},{'id':4,'name':'user4'}] function demo(url){ $.ajax({ method : 'POST', url : url, dataType: 'json', data : { objects :JSON.stringify(json)}, success : function(data){ console.log(data); }, error : function(error){ alert('OOps Something went wrong, please contact admin'); } }); } JSON.stringify()  method will parse the json object and convert it to a string format that can be sent as data in the Ajax call. you can also send other data with the json as follows var json = [{'id':1,'name':'us