Multi-tenancy: Managing multiple datasources with Spring Data JPA

To implement multi-tenancy with Spring Boot we can use AbstractRoutingDataSource as base DataSource class for all ‘tenant databases‘. It has one abstract method determineCurrentLookupKey that we have to override. It tells the AbstractRoutingDataSource which of the tenant datasource it has to provide at the moment to work with. Because it works in the multi-threading environment, … Read more

Spring Boot ClassNotFoundException org.springframework.core.metrics.ApplicationStartup

I was able to solve this by downgrading Spring Boot: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.3.3.RELEASE</version> </dependency> Guess it’s just not compatible with 2.4.0 yet. Specifically I also had to ensure that I used 2.3.3.RELEASE and not anything more recent due to other issues I ran across.

Spring Security: Upgrading the deprecated WebSecurityConfigurerAdapter in Spring Boot 2.7.0

I have managed to update the methods. This is the WebSecurityConfig class, and the methods are modified in the following way: public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception { authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder()); } has become: @Bean public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception { return authenticationConfiguration.getAuthenticationManager(); } Explanation: In the old version you inject AuthenticationManagerBuilder, set userDetailsService, passwordEncoder and … Read more

Spring boot – configure EntityManager

With Spring Boot its not necessary to have any config file like persistence.xml. You can configure with annotations Just configure your DB config for JPA in the spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver spring.datasource.url=jdbc:oracle:thin:@DB… spring.datasource.username=username spring.datasource.password=pass spring.jpa.database-platform=org.hibernate.dialect…. Then you can use CrudRepository provided by Spring where you have standard CRUD transaction methods. There you can also implement your … Read more

Gradle 5 JUnit BOM and Spring Boot Incorrect Versions

How do I disable JUnit coming from the Gradle Spring Dependency Management plugin? For starters, if you are using the dependency management plugin from Spring, you should not be importing the junit-bom since that results in duplicate (and potentially conflicting) management of those dependencies. Aside from that, whenever you use the dependency management plugin from … Read more

How to access in memory h2 database of one spring boot application from another spring boot application

You can setup H2 Server as Spring Bean. First edit pom.xml – delete <scope>runtime</scope> from h2 dependency: <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency> Then add H2 server bean to SpringBootApplication or Configuration class: @SpringBootApplication public class Application { public static void main(String[] args) {, args); } /** * Start internal H2 server so we can query … Read more