Results 1 to 2 of 2

Thread: configuration inheritance

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Posts
    2

    Default configuration inheritance

    Hi,
    supposed that, in the normal xml configuration file, i have:

    Code:
    <bean id="hibernateSessionFactory" class=".....LocalSessionFactoryBean"
    		lazy-init="true">
    		<property name="mappingResources">
    					<ref bean="somelist" />
    		</property>
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">${jdbc.dialect}</prop>
    				<prop key="hibernate.show_sql">${hibernate.show_sql}</prop> 
    				<prop key="hibernate.default_schema" >${jdbc.schema}</prop>
    				<prop key="hibernate.jdbc.batch_size" >20</prop>
    				<prop key="hibernate.cache.use_second_level_cache" >${hibernate.cache.use_second_level_cache}</prop>
    				<prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
    				<prop key="hibernate.cache.use_query_cache" >${hibernate.cache.use_query_cache}</prop>
    				<prop key="hibernate.cache.provider_configuration_file_resource_path=">ehcache.xml</prop>
    				<!-- prop key="hibernate.hbm2ddl.auto">create-drop</prop -->
    			</props>
    		</property>
    		<property name="dataSource">
    			<ref bean="${data.source}" />
    		</property>
    		<property name="lobHandler">
    			<bean
    				class="org.springframework.jdbc.support.lob.OracleLobHandler" />
    		</property>
    		<property name="entityInterceptor"><ref local="hibernateEntityInterceptor" /></property>
    		<property name="interceptorFilter" ref="interceptorFilter" />
    	</bean>
    
    <bean id="templateHibernateDAO" lazy-init="true">
    		<property name="sessionFactory">
    			<ref local="hibernateSessionFactory" />
    		</property>
    		<property name="maxResults" value="1000"/>
    	</bean>
    ...
    
    <bean id="DAO1"
    		class="..."
    		parent="templateHibernateDAO">
    
    	</bean>
    As you can see, DAO1's configuration inherit from templateHibernateDAO.

    however, i would like to configure all the beans above by javaconfig. here is my configuration
    Code:
    @Configurable
    @PropertiesValueSource(locations = "classpath:db/environment.properties")
    public abstract class AppCoreConfig {
    @Bean
    	public LocalSessionFactoryBean hibernateSessionFactory(){
    		LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean();
    		localSessionFactoryBean.setMappingResources(getMappingResources());
    		localSessionFactoryBean.setHibernateProperties(getHibernateProperties());
    		localSessionFactoryBean.setDataSource(getBasicDataSource());
    		localSessionFactoryBean.setLobHandler(new OracleLobHandler());
    		
    		//TODO: if we want to put an ADVICE, should put here
    		
    		return localSessionFactoryBean;
    	}
    	
    }
    ...
    my problem:
    in java configuration, i cant create a bean similar to the bean "templateHibernateDAO" in normal xml config. i find out that javaConfig does not support configuration inheritance. is there any way to support the config inheritance in javaConfig?
    please help me, thanks in advance

  2. #2
    Join Date
    Jul 2009
    Posts
    2

    Default let me make it clear in this way

    normal xml configuration:
    Code:
    <bean id="templateHibernateDAO" lazy-init="true">
    
    <property name="sessionFactory">
    <ref local="hibernateSessionFactory" />
    </property>
    <property name="maxResults" value="1000"/>
    </bean> <bean id="DAO1" class="..." parent="templateHibernateDAO">
    ...
    </bean>
    as you can see, the bean "DAO1" inherits the configuration from bean "templateHibernateDAO". we call it inheritance configuration

    however, in Spring JavaConfig, i could not find any example or document mention about this kind of configuration. please help me!
    i propose a solution for this. In my Appconfig.java
    Code:
    @Bean 
    public ClientDAO clientDAO(){
    
    ClientDAO client = new ClientDAO(); setup(client); ... return client;
    } private void setUp(HibernateDAO dao){
    dao.setSessionFactory((SessionFactory)hibernateSessionFactory().getObject());
    }
    ClientDAO extends HibernateDAO

    what do you think for this? pls pls

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •