|
From: Bill S. <bi...@gm...> - 2007-07-24 23:44:35
|
Spring developers,
First off, thank you very much for a wonderful framework.
I am in the process of writing a short paper on the Spring Framework in
which I exclusively use Spring programmatically. During this process, I've
found quite a few implementations of the InitializingBean interface that
have empty constructors, forcing me to call a few setter() methods, and
finally call an afterPropertiesSet() method to fully construct it. (I do
understand that when using an XML-based application context, the Spring
container calls the setters and afterPropertiesSet() for you. I want to use
Spring programmatically).
For example, in my Service Locator, I instantiate a LocalSessionFactoryBean
as follows:
private void initializeSessionFactory() throws Exception {
_localSessionFactoryBean = new LocalSessionFactoryBean();
Properties hibernateProperties = new Properties();
hibernateProperties.setProperty("hibernate.dialect","
org.hibernate.dialect.PostgreSQLDialect");
_localSessionFactoryBean.setDataSource(_dataSource);
_localSessionFactoryBean.setMappingResources(new
String[]{"com/billsix/examples/atm/DomainObjects.hbm.xml"});
_localSessionFactoryBean.setHibernateProperties(hibernateProperties);
_localSessionFactoryBean.afterPropertiesSet();
}
I prefer to create valid objects at construction time, so I would like the
following constructor.
public LocalSessionFactoryBean(DataSource dataSource, Properties
hibernateProperties, String[] mappingResources)
{
setDataSource(dataSource);
setHibernateProperties(hibernateProperties);
setMappingResources(mappingResources);
afterPropertiesSet();
}
This would allow me to instantiate a LocalSessionFactoryBean as follows:
private void initializeSessionFactory() throws Exception {
Properties hibernateProperties = new Properties();
hibernateProperties.setProperty("hibernate.dialect","
org.hibernate.dialect.PostgreSQLDialect ");
_localSessionFactoryBean = new
LocalSessionFactoryBean(_dataSource,hibernateProperties,new
String[]{"com/billsix/examples/atm/DomainObjects.hbm.xml"} );
}
I have found that some Spring classes offer both empty constructors as well
as constructors in the style I described above, such as the hibernate3
HibernateTransactionManager and the TransactionInterceptor. (Although,
TransactionInterceptor's constructors currently don't have calls
afterPropertiesSet() in the last line of each.)
If I create patches for InitializingBeans in which I'd like a constructor
with arguments, will they be accepted? If not, why not?
I've never contributed to an open source project before - I assume all I
have to do is to create "improvement" issues in JIRA, submitting patches for
each InitializingBean. Is that correct?
Thanks again,
Bill Six
|