DEV Community

Rahul Bhatt
Rahul Bhatt

Posted on

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

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

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
Enter fullscreen mode Exit fullscreen mode

That works, but I asked myself:

β€œWhat would it look like if Spring had built this?”

So I created:

@EnableTenantIsolation(strategy = TenantIsolationStrategy.SCHEMA)
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ 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 ✨

Top comments (0)