Code: Select all
@Component
@RequestScope
public class TenantContext {
@Getter @Setter
private String currentTenant=null;
}
@Component
@RequiredArgsConstructor
public class TenantIdentifierResolver implements CurrentTenantIdentifierResolver, HibernatePropertiesCustomizer {
private final TenantContext tenantContext;
private static String defaultValue="default";
@Override
public String resolveCurrentTenantIdentifier() {
return tenantContext==null?defaultValue:tenantContext.getCurrentTenant();
}
@Override
public void customize(Map hibernateProperties) {
hibernateProperties.put(AvailableSettings.MULTI_TENANT_IDENTIFIER_RESOLVER, this);
}
@Override
public boolean validateExistingCurrentSessions() {
return false;
}
}
Code: Select all
Error creating bean with name 'scopedTarget.tenantContext': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton
Code: Select all
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyModel = ScopedProxyMode.TARGET_CLASS)