SpringBoot : Working with JOOQ

In my previous article SpringBoot : Working with MyBatis we have learned how to use SpringBoot MyBatis Starter to quickly get up and running with Spring and MyBatis. In this article we are going to learn about how to use SpringBoot JOOQ Starter. JOOQ (JOOQ Object Oriented Querying) is a persistence framework which embraces SQL. JOOQ provides the following features: Building Typesafe SQL using DSL API Typesafe database object referencing using Code Generation Easy to use API for Querying and Data fetching SQL logging and debugging

Continue reading »

SpringBoot : Working with MyBatis

MyBatis is a SQL Mapping framework with support for custom SQL, stored procedures and advanced mappings. SpringBoot doesn’t provide official support for MyBatis integration, but MyBatis community built a SpringBoot starter for MyBatis. You can read about the SpringBoot MyBatis Starter release announcement at http://blog.mybatis.org/2015/11/mybatis-spring-boot-released.html and you can explore the source code on GitHub https://github.com/mybatis/mybatis-spring-boot. Create a SpringBoot Maven project and add the following MyBatis Starter dependency. <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.

Continue reading »

SpringBoot : Working with JdbcTemplate

Spring provides a nice abstraction on top of JDBC API using JdbcTemplate and also provides great transaction management capabilities using annotation based approach. First let’s take a quick look at how we generally use Spring’s JdbcTemplate (without SpringBoot) by registering DataSource, TransactionManager and JdbcTemplate beans and optionally we can register DataSourceInitializer bean to initialize our database. @Configuration @ComponentScan @EnableTransactionManagement @PropertySource(value = { "classpath:application.properties" }) public class AppConfig { @Autowired private Environment env; @Value("${init-db:false}") private String initDatabase; @Bean public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() { return new PropertySourcesPlaceholderConfigurer(); } @Bean public JdbcTemplate jdbcTemplate(DataSource dataSource) { return new JdbcTemplate(dataSource); } @Bean public PlatformTransactionManager transactionManager(DataSource dataSource) { return new DataSourceTransactionManager(dataSource); } @Bean public DataSource dataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.

Continue reading »

How SpringBoot AutoConfiguration magic works?

In my previous post Why SpringBoot? we have looked at how to create a SpringBoot application. But you may or may not understand what is going on behind the scenes. You may want to understand the magic behind the SpringBoot’s AutoConfiguration. But before that you should know about Spring’s @Conditional feature based on which all the SpringBoot’s AutoConfiguration magic depends. Exploring the power of @Conditional While developing Spring based applications we may come across of a need to register beans conditionally.

Continue reading »

Why SpringBoot?

Spring is a very popular Java based framework for building web and enterprise applications. Unlike many other frameworks which focuses on only one area, Spring framework provides a wide verity of features addressing the modern business needs via its portfolio projects. 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.

Continue reading »

Retrying Method Execution using Spring AOP

One of my blog follower sends an email asking me to show an example of “RealWorld Usage of Spring AOP”. He mentioned that in most of the examples the usage of Spring AOP is demonstrated for logging method entry/exit or Transaction management or Security checks. He wanted to know how Spring AOP is being used in “Real Project for Real Problems”. So I would like to show how I have used Spring AOP for one of my project to handle a real problem.

Continue reading »

JCart : Iteration-8

In this Iteration#8 we will implement showing the Customer Account and Order History functionality in our ShoppingCart application. Customer MyAccount Page Profile Order History Once the customer is logged in our system he can click on MyAccount link at the top of the header and view his profile details and order history. First let us write the Controller handler method in our CustomerController to show myAccount details. @Controller public class CustomerController extends JCartSiteBaseController { @Autowired private CustomerService customerService; .

Continue reading »

JCart : Manage Customers

For Managing Customers we need a provision to see all the list of customers and view any Customers details. Let us start with implementing the back-end Customer service. public interface CustomerRepository extends JpaRepository<Customer, Integer> { Customer findByEmail(String email); @Query("select o from Order o where o.customer.email=?1") List<Order> getCustomerOrders(String email); } @Service @Transactional public class CustomerService { @Autowired CustomerRepository customerRepository; public Customer getCustomerByEmail(String email) { return customerRepository.findByEmail(email); } public Customer createCustomer(Customer customer) { return customerRepository.

Continue reading »

JCart : Manage Orders

For Managing Orders we need a provision to see all the list of orders and view an order details and updating the order status. Let us start with implementing the back-end order service. @Service @Transactional public class OrderService { @Autowired EmailService emailService; @Autowired OrderRepository orderRepository; ... ... public Order getOrder(String orderNumber) { return orderRepository.findByOrderNumber(orderNumber); } public List<Order> getAllOrders() { Sort sort = new Sort(Direction.DESC, "createdOn"); return orderRepository.findAll(sort); } public Order updateOrder(Order order) { Order o = getOrder(order.

Continue reading »

JCart : Iteration-7

In Iteration#6 we have implemented features in ShoppingCart application to enable Customers place orders. In this Iteration#7 we will implement the features in Administration application to view and manage the Customers and Orders. As part of Iteration#7 we will implement the following usecases: Manage Orders List all Orders View Order details Update Order status Manage Customers List all customers View customer details

Continue reading »