Posts

Showing posts with the label tutorial

AWS DynamoDB Table Design in 10 mins

Image
AWS DynamoDB is a serverless, key and value pair NOSQL database. The schema design concept is different from traditional relational database. You can understand the DynamoDB table design within 10 minutes in this video. 

Develop Spring boot REST API in AWS - PART 4/4 (CodePipeline / CI CD)

Image
This is the last video (part4) in this demo series. We will demonstrate how to create the whole CICD pipeline in this tutorial video. It involves the following steps: (1)  Create CodePipeline (2) Add build stage to pipeline (3) Add deploy stage to pipeline (4) Add manual approval step to pipeline Thank for watching! Source Code: https://github.com/babysteps-topro/aws-springboot-pipeline1.git

Develop Spring boot REST API in AWS - PART 3/4 (CodeDeploy / Blue Green Deployment)

Image
In this video tutorial (part3), I have demonstrate the blue/green deployment of  the Spring boot REST API.  I will show you the the following steps in the demonstration: (1)  02:12 Create IAM role (2)  04:07 Create an Application Load Balancer (3)  07:27 Create Security Group For ECS cluster (4)  09:09 Create ECS cluster (5)  11:24 Create Task Definition (6)  14:00 Create ECS Service (7)  17:53 Create CodeDeploy In the next part, I will demonstrate the whole CI/CD pipeline.

Lightweight Web Application Framework: PrimeFaces (JSF) + Guice + MyBatis (PART 2)

In this part, I will continue to demonstrate the integration of JSF, Guice and MyBatis. DBCP connection pool and MYSQL database is used in persistence layer Integrate Google Guice with MyBatis In the previous post, we have created a ServletContextListener. Now, we just bind the BasicDataSourceProvider and JdbcTransactionFactory in the contextInitialized method. GuiceContextListener.java package org.borislam; import java.util.Properties; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; import org.apache.log4j.xml.DOMConfigurator; import org.borislam.mapper.StaffMapper; import org.borislam.service.SimpleService; import org.borislam.service.impl.SimpleServiceImpl; import org.mybatis.guice.MyBatisModule; import org.mybatis.guice.datasource.dbcp.BasicDataSourceProvider; import org.mybatis.guice.datasource.helper.JdbcHelper; import com.google....

Lightweight Web Application Framework : PrimeFaces (JSF) + Guice + MyBatis (PART1)

Recently, my friend asks me how to build a lightweight java web application. Many Java web developer would choose Spring and hibernate to build a traditional web application. However, it may not be lightweight enough. I suggested him try to use Guice and MyBatis to build the application framework. Although Spring is more feature-riched than Guice, I admitted that Guice is more lightweight and easier to use. MyBatis is also a lightweight SQL map framework. It can integrate with Guice framework very well. Here, I will try to set up a simple web application with PrimeFaces, Guice and MyBatis. I hope that my friend could learn how to do it. :) Using MyFaces and PrimeFaces in presentation layer. Integrate MyFaces and PrimeFaces is simple. Just simply get the JARS file from MyFaces website and PrimeFaces website . For MyFaces, just add the following sample configuration into your web.xml. <display-name>TestGuice</display-name> <context-param> <param-name...

Writing your spring security expression language annotation - PART 3

In the last part of tutorial, I will discuss how to override the behaviour of defualt spring security method expression. You may wonder why I need to override the default behaviour of these methods. The reason behind is that, in recent development project, we are reviewing the developer's code and we hope to maintain a standard coding practice. We find that the default method expression is too flexible. In our case, under similar coding scenario, some developers use hasRole() for security checking while other developers using hasPermission() for security checking. In order to keep the maintainability of the program, we thus have an idea to disallow developer to use certain secruity method expression. That's why we have the crazy idea of overriding the default behaviour of these methods. (This may not be a good idea :P. But anyway, we have implement it :D) In this example, I simply show how to override the default behaviour of hasRole() method. You can not do this by override ...

Writing your spring security expression language annotation - PART 2

We are now going into the second part of the tutorial. In this post, it will show you how to add a new custom expression for @PreAuthorize annotation. For example, I will show how to add a adminOnly() expression language to the security expression root. Step 1: Define your custom security expression root class You have to first create a new security expression root class. This class should be extended from the abstract class org.springframework.security.access.expression.SecurityExpressionRoot. You can add your custom This class is similar to org.springframework.security.access.expression.method.MethodSecurityExpressionRoot but with your new custom method added. As an example, I just add a very simple mehod adminOnly() which check if the user has admin role. public class MyMethodSecurityExpressionRoot extends SecurityExpressionRoot { private static Logger logger = LoggerFactory.getLogger(MyMethodSecurityExpressionRoot.class); private Object filterObject; priva...

Adding Hibernate native SQL features into your Spring Data Repository

JPA provides @NamedNativeQuery for you to use native SQL. However, the usage is not so convenient, especially when you need to map multiple entities in your native SQL. You have to define a set of SqlResultSetMapping mapping which is quite error prone. For those who have used Hibernate native SQL features before, you will find that it is much more easier to use than JPA's @NamedNativeQuery. In recent projects, I am using Spring Data JPA. I have added hibernate native query features to my Spring Data base repostory. You can now perform native query in JPA without SqlResultSetMapping. 1. Add you cusomt annotation @NativeQueries and @NativeQuery @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface NativeQueries { NativeQuery[] queries() default {}; } @Retention(RetentionPolicy.RUNTIME) public @interface NativeQuery { String name() default ""; String sql() default ""; } 2. Add the method "queryNatively" in base Spri...

Customizing Spring Data JPA Repository

Spring Data is a very convenient library. However, as the project as quite new, it is not well featured. By default, Spring Data JPA will provide implementation of the DAO based on SimpleJpaRepository. In recent project, I have developed a customize repository base class so that I could add more features on it. You could add vendor specific features to this repository base class as you like. Configuration You have to add the following configuration to you spring beans configuration file. You have to specified a new repository factory class. We will develop the class later. <jpa:repositories base-package="example.borislam.dao" factory-class="example.borislam.data.springData.DefaultRepositoryFactoryBean/> Just develop an interface extending JpaRepository. You should remember to annotate it with @NoRepositoryBean. @NoRepositoryBean public interface GenericRepository <T, ID extends Serializable> extends JpaRepository<T, ID> { } Define...