Creating Spring Boot MVC application with AWS DynamoDB in 10 mins

AWS DynamoDB DB is a serverless NOSQL database. You can understand how to build a spring boot Java web MVC application (Game Leaderboard) reading a AWS DynamoDB in 10 mins. Source of the demo code: Command to run the project: mvn spring-boot:run Video explain the table design: Prerequisite: Install the AWS CLI: Video explain the how to create the table:

Inject SLF4J logger by annotation

Actually, the following class is not written by me. It is written my colleage. I know he is referencing from another post from Java Geeks. I found this is quite handy so I put it here as a reference.

The main idea is make use of the BeanPostProcessors interface. We first create an "LoggableInjector" class which implement the BeanPostProcessors interface.
This injector class gets the SLF4J logger and assign to the beans property after the bean creation by the Spring IOC continaer.

1. Create Loggable annotation
public @interface Loggable {
 //for slf4j

2. Create LoggableInjector class to add logger to the bean
public class LoggableInjector implements BeanPostProcessor {        
 public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {  
  return bean;  
 public Object postProcessBeforeInitialization(final Object bean, String beanName) throws BeansException {  
  ReflectionUtils.doWithFields(bean.getClass(), new FieldCallback() {  
   public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {  
    // make the field accessible if defined private  
    if (field.getAnnotation(Loggable.class) != null) {
     Logger log = LoggerFactory.getLogger(bean.getClass());      
     field.set(bean, log);  
  return bean;  

3. Usage Example

public class ReportServiceImpl {

 private Logger logger;


Popular posts from this blog

Sample Apps: Spring data MongoDB and JSF Integration tutorial (PART 1)

Customizing Spring Data JPA Repository

Adding Hibernate Entity Level Filtering feature to Spring Data JPA Repository