Day 3 : DX-First Thinking: Why I Added @EnableTenantIsolation to My Spring Boot Starter

Code StrikerCode Striker
1 min read

Day 3 of building multi-tenant-springboot-starter was less about code, more about mindset.

I wanted developers to switch between DATABASE, SCHEMA, and SHARED isolation strategies for tenants. The default Spring Boot way would be application.yml:

tenant:
  strategy: DATABASE

That works, but I asked myself:

“What would it look like if Spring had built this?”

So I created:

@EnableTenantIsolation(strategy = TenantIsolationStrategy.SCHEMA)

💡 This annotation uses ImportBeanDefinitionRegistrar and EnvironmentAware to inject the tenant.strategy key into the Spring Environment — before anything binds.

What I learned: Boot auto-config works great, but it doesn't understand your custom annotations — unless you bridge them using @Import(...)

The BEAN_CONTAINER trick in JPA is mandatory when manually wiring multiple EntityManagerFactoryBeans — without it, entity scanning breaks

Key Takeaway: Framework-level DX is about thinking like Spring, not just using it.

Tomorrow: schema-per-tenant Hibernate integration.

Repo: github.com/rahul-s-bhatt/multi-tenant-springboot-starter

Follow for more build-in-public logs ✨

0
Subscribe to my newsletter

Read articles from Code Striker directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Code Striker
Code Striker