Announcement Announcement Module
Collapse

JavaConfig forum decommissioned in favor of Core Container

As described at

http://static.springsource.org/sprin...fig/README.TXT

key features of the Spring JavaConfig project have been migrated into the core Spring Framework as of version 3.0.

Please see the Spring 3.0 documentation on @Configuration and @Bean support:

http://static.springsource.org/sprin...tml#beans-java

For any questions related to @Configuration classes and @Bean methods in Spring 3.0, please post in the dedicated 'Core Container' forum at

http://forum.springsource.org/forumdisplay.php?f=26
See more
See less
configuration inheritance Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment

    Working...
    X