Posts

Synchronization in JAVA

Image
You should be aware of Synchronization if you are working on an application where multiple threads are accessing the same resources or else it will show you erroneous or unforeseen results. Imagine a scenario where you are doing the multiple transactions in your bank. I believe you don’t want one thread is updating your balance and in parallel, the other thread is reading your balance otherwise you will end up in error or unexpected results. Example 1: Public class HDFCBank {             Protected long balanace =1000;             Public void deposit( int amount) {                         this.balance = this.balance + amount;             } } Assume if two threads, A and B are executing t...

FAQ Questions on Spring Boot

How to control logging with Spring Boot? By default, the SLF4j Logging is included in the Spring Boot starter package. To enable logging, create a  application.properties  file in the root of the  resources  folder. 1. application.properties logging.level.org.springframework.web=ERROR logging.level.com.waheedtechblog=DEBUG # Logging pattern for the console logging.pattern.console= "%d{yyyy-MM-dd HH:mm:ss} - %msg%n" # Logging pattern for file logging.pattern.file= "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n" logging.file=/Users/waheed/application.log Similarly we can configure in application.yml as well. 2. application.yml logging:   level:     org.springframework.web: ERROR     com.waheedtechblog: DEBUG   pattern:     console: "%d{yyyy-MM-dd HH:mm:ss} - %msg%n"     file: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{3...

Database access with Spring boot

Image
The simplest way of creating Spring boot with MySQL application is via Spring starter project using STS (Spring Tool Suite) IDE. Steps: Create a new project by selecting spring starter project wizard Select project type as Maven, provide project name, packaging, and Java version etc. Select spring boot version and project dependencies After finishing, It will create the project structure with all required dependency. Configure MySQL configuration in application.properties file Now, Create the @Entity model ( User ) which should be persisted in the database . Hibernate will automatically translate entity class into a table. Create the repository (UserRepository.java ) . The Repository interface will be automatically implemented by Spring in a bean with the same name with changing case. For UserRepository, the bean name will be  userRepository . To handle HTTP request, Create a Controller class (UserController.java) having method POST a...

Spring Boot application Example

Image
As we know that there are various ways for creating Spring Boot application. For this sample application, I am going to use STS (Spring Tool Suite) IDE. Steps: Create a new project by selecting spring starter project wizard Select project type as Maven, provide project name, packaging, and Java version etc. Select spring boot version and project dependencies After finishing, you can see the project structure as shown below Spring boot generates a Java file in the  src/main/java  directory, pom.xml file with all required dependency.  T o handle HTTP request, Create a Controller class Now run the  SpringBootExampleApplication.java  as a Java application. It will start the tomcat server on default port i.e. 8080 Open browser and hit url http://localhost:8080/application Note: By Default, Application will start on port 8080 but can override by adding server.port to application.properties file....

What is Spring Boot Initilizr?

Image
Spring Boot Initilizr is a web tool which is provided by Spring on official site using which Spring Boot project can be created by providing project details. It simplifies Spring Applications Development by providing initial project structure and build scripts which reduces development time thus increase productivity. Steps to create Spring Boot project via initilizr ·         Select Maven project and dependencies. Fill other details as shown below and click on generate project. ·         Download the project, extract and now import this project As Maven by using Import option from the STS (Spring Tool Suite) IDE. ·         After finishing, You can see the project structure as shown below: ·      Spring boot generates a Java file in the  src/main/java  directory, pom.xml file with all required dependency. The default created Java ...

Introduction to Spring Boot

Spring Boot is another module provided by Spring Framework which provides RAD (Rapid Application Development) feature to Spring framework. Using boot, we can create standalone Spring based application that you can “just run” in no time and Most Spring Boot applications need very little Spring configuration and it does not require any XML configuration. It uses convention over configuration software design paradigm that means it decrease the effort of developer. Why Spring Boot? As we know Spring framework provides flexibility to configure the beans in multiple ways such as  XML, Annotations  and  JavaConfig. With the number of features increased the complexity also gets increased and configuring Spring applications becomes tedious and error-prone. Spring Boot: ·          Ease the dependency Management , Java-based applications Development, Unit Test and Integration Test Process. Eg: By adding springboot-starte...

Shibboleth Idp with External Authn Configuration

Image
Shibboleth Idp comes with by default various flows like UsernamePassword, Mfa, X509, Kerberos, Spengo and various others flow but today I am going to discuss in details about one more flow which is also provided by Shibboleth Idp itself i.e External Flow Use case: Shibboleth Idp supports external Authn flow using which specific requirement can be fulfilled like your authentication database resides at some other location or some other servlet will do the authentication on the Idp’s behalf like authentication should be done at Facebook or Google side. All such scenario can be easily handled using External Authn flow. Shibboleth team has already created document for the same which you can read it over here . I am writing this document to explain it in more details with example. There are few predefined steps that we need to follow to add new custom flow in Shibboleth Idp as per Shibboleth guidelines. Let’s assume we have to create new flow named “Authn/Custom” in Shibbolet...