Announcement Announcement Module
Collapse
No announcement yet.
@Configurable in spring initialization Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Configurable in spring initialization

    Hi,

    I'm trying to configure MultiTenant in LocalSessionFactoryBean and xml looks like this:

    Code:
    <context:spring-configured/>	
    <context:component-scan base-package="xpro.xmanager.xutil.hibernate"/>
    
    <bean id="connectionProvider" 
    	class="xpro.xmanager.xutil.hibernate.MultiTenantConnectionProviderImpl" 
    	scope="prototype">
    	<property name="tenancyService" ref="tenancyService"/>		
    </bean>	
    
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    	<property name="dataSource"><ref local="dataSource"/></property>
    	<property name="mappingLocations">
    		<list>
    			<value>classpath:xpro/xmanager/dao/impl/**/*.hbm.xml</value>
    		</list>
    	</property>
    	<property name="hibernateProperties">
    		<props>
    			<prop key="hibernate.dialect">${hibernate.dialect}</prop> 
    			<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
    			<prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
    			<prop key="hibernate.connection.isolation">${hibernate.connection.isolation}</prop>
    			<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
    			<prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
    			<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
    			<prop key="hibernate.tenant_identifier_resolver">xpro.xmanager.xutil.hibernate.CurrentTenantIdentifierResolverImpl</prop>
    			<prop key="hibernate.multi_tenant_connection_provider">xpro.xmanager.xutil.hibernate.MultiTenantConnectionProviderImpl</prop>	        
    			<prop key="hibernate.multiTenancy">DATABASE</prop>
    		</props>
    	</property>
    </bean>
    The code of MultiTenantConnectionProviderImpl is:

    Code:
    @Configurable(value="connectionProvider", preConstruction=true)
    public class MultiTenantConnectionProviderImpl extends AbstractDataSourceBasedMultiTenantConnectionProviderImpl {
    	
    	private Map<String, DataSource> map;
    	
    	private TenancyService tenancyService;
    	
    	public MultiTenantConnectionProviderImpl() {
    		System.out.println(tenancyService);
    	}
    
    	public void setTenancyService(TenancyService tenancyService) {
    		this.tenancyService = tenancyService;
    	}
    }
    The problem is the tenancyService is null, even with preConstruction true. I'm getting this warning in context initialization:

    03/12/12 18:07:56 [main] DEBUG beans.factory.wiring.BeanConfigurerSupport:123 - BeanFactory has not been set on BeanConfigurerSupport: Make sure this configurer runs in a Spring container. Unable to configure bean of type [xpro.xmanager.xutil.hibernate.MultiTenantConnectio nProviderImpl]. Proceeding without injection.

    This problem is happening only with this class. I think that "spring context" is not ready when my MultiTenantConnectionProviderImpl is instantiated. Am I right? What I supposed to do?

    Thanks in advance
Working...
X