Spring Application Code
------------------------------
public class StudentEnroller implements EnrollAStudent{
private Resource resource;
private BeanFactory factory;
private DataSource ds;
private JdbcTemplate jt;
public StudentEnroller(){
try{
resource=new ClassPathResource("Enrollment-Config.xml");
factory=new XmlBeanFactory(resource);
ds=(DataSource)factory.getBean("dataSource");
jt=new JdbcTemplate (ds);
}catch(Exception e){
//....
//log the error
}
}
There's nothing earth-shattering here!
Spring provides a choice though, you can inject dependency rather than looking for it.
Get away with Spring/Hibernate
2006-04-27 22:04:13
JasonSherman
[View]
Who liked to program in Spring or Hibernate? If you are still using Spring or planning to use frameworks like Spring or Hibernate, then you make give EB 3.0 a serious thought. After all, nobody likes clumsy XML code. Both, Spring and Hibernate make heavy use of XML documents. Prior to EJB 3.0, delivering container services has never been so easy before.
With regard to this article, it’s targeted towards small to medium size applications which have a small footprint and don’t require a heavyweight EJB container. I think we must give some credit to the author, cause towards the end, he does mention about out-of-box connection pooling features available in peculiar J2EE environment. Moreover, there are good numbers of developers who are just happy with a simple servlet container like Tomcat and want to explore more into it.
Spring Code (Enrollment-Config.xml)
-------------------------------------
<beans>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost/dbcptest</value>
</property>
</bean>
</beans>
Spring Application Code
------------------------------
public class StudentEnroller implements EnrollAStudent{
private Resource resource;
private BeanFactory factory;
private DataSource ds;
private JdbcTemplate jt;
public StudentEnroller(){
try{
resource=new ClassPathResource("Enrollment-Config.xml");
factory=new XmlBeanFactory(resource);
ds=(DataSource)factory.getBean("dataSource");
jt=new JdbcTemplate (ds);
}catch(Exception e){
//....
//log the error
}
}
There's nothing earth-shattering here!
Spring provides a choice though, you can inject dependency rather than looking for it.