Skip to main content

Disable Datasource Auto Configuration in Spring Boot

Today morning, We had an interesting situation. Our spring boot application which is configured to run on MySQL needs to be run on a system which does not have MySQL database installed. But we had to develop few UI modules alone. So we decided to go ahead but how do we disable MySQL database auto-configuration?

Here is what we did.

Spring Boot is an interesting framework that helps auto configure everything for you. In case you need to override any of the auto-configuration, all you need to do is to simply customize it. The auto-configuration backs away. In this typical scenario, we dont want to customize the auto-configuration, rather we want to disable it temporarily until we complete our UI modules. As soon as the system is ready or we find alternate systems, we can run the Application with full-blown schema.

OK. so how did we disable the database auto configuration?

We are using Spring Boot with JPA, Hibernate and FlywayDB migration tool. If this is going to be your boot application config, you first need to exclude auto configuration of the below classes.
  1. DataSourceAutoConfiguration.class
  2. HibernateJpaAutoConfiguration.class
 * @author abuabdul
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, 
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {, args);

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);


What next?

We will need to disable all autowired repository beans. To do that, you just use required=false attribute in the @Autowired annotation. Generally, disable all the beans that require datasource configuration in whatever ways that fit into your application configuration and coding style.

public class AppUserDetailsService implements UserDetailsService {

    private final Logger LOG = LogManager.getLogger(AppUserDetailsService.class);

    @Autowired(required = false)
    private AppUserRepository appUserRepository;

Finally, Since you are using FlywayDB migration tool, you can optionally disable it using flyway.enabled = false. But keeping flywaydb enabled is not going to harm as we already disabled datasource and hibernate jpa auto configuration.

Assumption      : Spring Boot (1.5.6),  Flyway(4.2.0), Maven Projects


  1. Oh, arrive on! This is a very awesome post! But you some, if
    you necessity assistance with essay and homework you can ask this guys for help! They rally know how to do it, and you'll not waste your money and time!


Post a Comment

Popular posts from this blog

CSRF enabled Ajax requests using Spring Security

Many of you who have worked on Spring Security might be aware of the fact that Spring Security protects applications from Cross Site Request Forgery using _csrf tokens in the request sent to the web server. You can find a detailed understanding in the Spring documentation page . The objective of this post is to explain how to send _csrf tokens in the Ajax requests when we protect our application URL and application access using spring security. How to get CSRF tokens While we submit a form using an application that is protected with Spring Security, the form gets a default hidden parameter in the form body when using <form:form> element. The param contains the _csrf tokens to authenticate the requests in the server. In case we use other ways to create forms, we have to manually include a hidden parameter that contains name as ${_csrf.parameterName} and  value as ${_csrf.token} . For example, <input type= "hidden" name= "${_csrf.parameterName}"

A wonderful technique to reduce website development cost

Websites - Good way to get online presence Websites are very vital to get online presence of any business nowadays. Websites are categorized into two different types. First one is Static Website and second one is Dynamic Website, normally known as web applications. Static websites are most widely used for any business since they help to bring up the online presence more easily and quickly. Depending on the content and features, static websites cost around $300-$700 . It includes web design and development. Apart from that, the business has to spend for hosting space and domain name for the website. Cloud based development is now more prevalent. Building a website and running it will be very easy and cheap using these cloud infrastructure. But the difficulty facing the development of static websites still looms high as it does not matter who provides the infrastructure. The development cost is still same. Technology - LAMP Static websites are developed using HTML and PHP mostly