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.
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.
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
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.
- DataSourceAutoConfiguration.class
- HibernateJpaAutoConfiguration.class
/**
* @author abuabdul
*/
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class,
HibernateJpaAutoConfiguration.class})
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
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.
@Service
@Transactional
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
Oh, arrive on! This is a very awesome post! But you some, if https://www.phdresearch.net/
ReplyDeleteyou 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!
scatter 888 ยืนหนึ่งในเรื่องที่เกี่ยวข้องกับการให้บริการกับเว็บไซต์ pg slot เรามีระบบระเบียบแอดไม่นรอให้แก่ท่านข้ามาสัมผัสการบริการ ที่มีปัญหาเมื่อคุณอยากได้เข้าสัมผัสการเดิมพัน
ReplyDeletemovewinbet เว็บไซต์สลากกินแบ่งออนไลน์ ชั้น1 ลอตเตอรี่ออนไลน์มีครบจบในเว็บไซต์เดียวสมัครฟรี pg slot ฝากอัตำหนิโนมั ฮานอย มาเลย์ ลาว ยี่กี พวกเรามีครบ มีโปรโมชั่นเอาอกเอาใจลูกค้า
ReplyDelete