Problem SpringBoot provides lot of flexibility in externalizing configuration properties via properties or YAML files. We can also configure properties for each environment (dev, qa, prod etc) separately using profile specific configuration files such as application.properties, application-dev.properties, application-prod.properties etc. But once the application is started we can not update the properties at runtime. If we change the properties we need to restart the application to use the updated configuration properties.
Continue reading »Getting Started with SpringBoot in Intellij IDEA Community Edition
We can use Intellij IDEA Community Edition for working with SpringBoot applications as we don’t need support for configuring servers like Tomcat, Wildlfy etc and can simply run the applications by running main() method. However, there is no provision in Intellij IDEA Community Edition to create SpringBoot application directly, the way it supports in Ultimate Edition. We can go to http://start.spring.io/ and generate the project and then import into our IDE.
Continue reading »Update on SpringBoot : Learn By Example book
I would like to let you know that I have updated/added the following sections to my SpringBoot : Learn By Example book. Additions to existing chapters: Working with Multiple Databases Exposing JPA entities with bi-directional references through RESTful services In some of our applications we need to work with multiple databases. For example, we may have a primary database and a reporting database where most the application uses primary database and the application reports will be generated out of reporting database data.
Continue reading »How to fix “vt-x is disabled in the bios” error?
If you face the vt-x is disabled in the bios error while trying to run Android emulator, here is the solution that worked for me. Step 1: Enable Virtualization Technology in BIOS Go to BIOS Setup and enable “Virtualization Technology” option. On my Lenovo laptop this option was already enabled, but still getting this error. I have disabled it and re-enabled it, then it is working. Step 2: Install HAXM Installer from Android SDK Manager Start the Android SDK Manager, select Extras -> Intel x86 Emulator Accelerator (HAXM Installer) and install it.
Continue reading »My New Book SpringBoot : Learn By Example Published Today
I am happy to announce that my new book SpringBoot : Learn By Example got published today on Leanpub. What is SpringBoot? Spring is one of the most popular Java frameworks out there to build web and enterprise application. Spring supports variety of configuration approaches (XML, Annotations, JavaConfig etc) and properly configuring Spring applications become a bit tedious and repetitive process. To avoid these problems Spring team introduced SpringBoot to address the complexity of configuring Spring application.
Continue reading »Creating Custom SpringBoot Starter for Twitter4j
SpringBoot provides lot of starter modules to get up and running quickly. SpringBoot’s auto-configure mechanism takes care of configuring SpringBeans on our behalf based on various criteria. In addition to the springboot starters that comes out-of-the-box provided by Core Spring Team, we can also create our own starter modules. In this post we will look into how to create a custom SpringBoot starter. To demonstrate it we are going to create twitter4j-spring-boot-starter which will auto-configure Twitter4J beans.
Continue reading »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 »