Hi group -
I am trying out a simple Schema based Multitenancy using Single Datasource.
Did configure
Code:
<prop key="hibernate.multiTenancy">SCHEMA</prop>
<prop key="hibernate.multi_tenant_connection_provider">org.dao.MultiTenantConnectionProviderForSchema</prop>
<prop key="hibernate.tenant_identifier_resolver">org.dao.MultiTenantResolver</prop>
and I am trying to set the schema using the connection with set SCHEMA 'tenantid' in the MultiTenantConnectionProviderForSchema class.
Getting struck here, as i am not able to inject the datasource into the @component class, eventhough it is autowired
Has anyone resolved it?
Below is my beans.xml
Code:
<context:component-scan base-package="org.dao"/>
<context:annotation-config />
<bean name="dataSource" id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/postgres" />
<property name="username" value="postgres" />
<property name="password" value="root" />
</bean>
<bean name="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="packagesToScan" value="org.entity"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.multiTenancy">SCHEMA</prop>
<prop key="hibernate.multi_tenant_connection_provider">org.dao.MultiTenantConnectionProviderForSchema</prop>
<prop key="hibernate.tenant_identifier_resolver">org.dao.MultiTenantResolver</prop>
</props>
</property>
</bean>
<bean name="NodeDAO" class="org.dao.NodeDAO">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>