Skip to main content


Showing posts with the label Spring Framework

Spring Security - Form based authentication

In this post, we will use Spring security to handle form based authentication. You can also read my previous posts on Basic Authentication and Digest Authentication . Technologies/ Frameworks used Spring Boot, Spring Security, Thymeleaf, AngularJS, Bootstrap Adding depedencies in pom.xml In the example, we will use Spring Boot, Spring Security, Undertow and thymeleaf and will add their starters as shown below. <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-undertow</artifactId> <

Spring Boot - ApplicationRunner and CommandLineRunner

Spring Boot provides two interfaces CommandLineRunner and ApplicationRunner to run specific piece of code when application is fully started. These interfaces get called just before run() on SpringApplication completes. CommandLineRunner This interface provides access to application arguments as string array. Let's see the example code for more clarity. @Component public class CommandLineAppStartupRunner implements CommandLineRunner { private static final Logger logger = LoggerFactory.getLogger(CommandLineAppStartupRunner.class); @Override public void run(String... args) throws Exception {"Application started with command-line arguments: {} . \n To kill this application, press Ctrl + C.", Arrays.toString(args)); } } ApplicationRunner ApplicationRunner wraps the raw application arguments and exposes interface ApplicationArguments which have many convinent methods to get arguments like getOptionNames() return all the arguments names

Spring Boot - A quick start

In this post, we will create a simple Spring Boot application which will run on embedded Apache Tomcat. What is Spring Boot? Spring Boot helps in creating stand-alone, production-grade application easily with minimum fuss. It is the opinionated view of Spring framework and other third party libraries which believes in convenient configuration based setup. Let's start building Spring Boot Application. Adding dependencies in pom.xml We will first add spring-boot-starter-parent as parent of our maven based project. <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.1.RELEASE</version> </parent> The benefit of adding spring-boot-starter-parent is that version managing of dependency is easy. You can omit the required version on the dependency. It will pick the one configured the parent pom or from starters pom. Also, it conveniently setup the build r