<project ……> …… <dependencies> …… <dependency> <!-- [Spring 3] and [Hibernate 3] advanced integration. --> <groupId>org.springframework</groupId> <artifactId>spring-hibernate</artifactId> <version>1.2.8</version> </dependency> </dependencies> </project>
<?xml version="1.0" encoding="UTF-8"?> <beans ……> …… <bean id="crud.hibernate.urlMapping" ……> …… </bean> <!-- [########################################] --> <bean id="crud.hibernate.advanced.sf" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="ds"/> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.formate_sql">true</prop> </props> </property> <property name="mappingResources"> <list> <value>tfw/integration_demo/_04_spring_web_mvc/_02_crud/_04_hibernate_crud/dao/impl/oracle/User.hibernate_mapping.xml</value> </list> </property> </bean> </beans>
public class _01_HibernateDAO_with_Spring
{
private String strSpringClassPathConfFile =
"tfw/integration_demo/_04_spring_web_mvc/applicationContext.xml";
@Test
public void testObjects2() throws IOException
{
System.out.println(
"Spring Configuration File:\n\t" + strSpringClassPathConfFile);
AbstractApplicationContext actxt =
new ClassPathXmlApplicationContext(strSpringClassPathConfFile);
System.out.println("Application Context:\n\t" + actxt);
SessionFactory sf = actxt.getBean("crud.hibernate.advanced.sf",
SessionFactory.class);
System.out.println("SessionFactory:\n\t" + sf);
Session session = sf.openSession();
System.out.println("Session:\n\t" + session);
Transaction ts = session.beginTransaction();
System.out.println("Transaction:\n\t" + ts);
session.close();
System.out.println("Session Closed:\n\t" + session);
actxt.close();
System.out.println("Application Context Closed:\n\t" + actxt);
}
}
<?xml version="1.0" encoding="UTF-8"?> <beans ……> …… <!-- [########################################] --> <bean id="crud.hibernate.advanced.sf" ……> …… </bean> <bean id="crud.hibernate.advanced.userDAO" class="tfw.integration_demo._04_spring_web_mvc._02_crud._04_hibernate_crud._01_basic_way.dao.UserDAO"> <constructor-arg ref="crud.hibernate.advanced.sf"/> </bean> </beans>
…… public class _01_HibernateDAO_with_Spring extends A_UserMgrTestCaseBase { private String strSpringClassPathConfFile = "tfw/integration_demo/_04_spring_web_mvc/applicationContext.xml"; private AbstractApplicationContext actxt; private I_UserDAO userDAO; @Test public void testObjects2() throws IOException { …… session.close(); System.out.println("Session Closed:\n\t" + session); I_UserDAO userDAO = actxt.getBean("crud.hibernate.advanced.userDAO", I_UserDAO.class); System.out.println("DAO:\n\t" + userDAO); actxt.close(); System.out.println("Application Context Closed:\n\t" + actxt); } @Before public void init() throws IOException { System.out.println( "Spring Configuration File:\n\t" + strSpringClassPathConfFile); actxt = new ClassPathXmlApplicationContext(strSpringClassPathConfFile); System.out.println("Application Context:\n\t" + actxt); userDAO = actxt.getBean("crud.hibernate.advanced.userDAO", I_UserDAO.class); System.out.println("DAO:\n\t" + userDAO); } @After public void close() { actxt.close(); System.out.println("Application Context Closed:\n\t" + actxt); } @Test public void testUserDAO_create() throws SQLException { …… } …… }
<?xml version="1.0" encoding="UTF-8"?> <beans ……> …… <bean id="crud.hibernate.advanced.userDAO" ……> …… </bean> <bean id="crud.hibernate.advanced.userMgrSvc" class="tfw.integration_demo._04_spring_web_mvc._02_crud._01_basic_jdbc_crud.service._01_UserMgrService"> <property name="userDAO" ref="crud.hibernate.advanced.userDAO"/> </bean> </beans>
…… public class _01_HibernateDAO_and_Service_with_Spring extends A_UserMgrTestCaseBase { …… private I_UserDAO userDAO; private _01_UserMgrService userMgrSvc; @Test public void testObjects2() throws IOException { …… I_UserDAO userDAO = actxt.getBean("crud.hibernate.advanced.userDAO", I_UserDAO.class); System.out.println("DAO:\n\t" + userDAO); _01_UserMgrService userMgrSvc = actxt.getBean( "crud.hibernate.advanced.userMgrSvc", _01_UserMgrService.class); System.out.println("Service:\n\t" + userMgrSvc); actxt.close(); System.out.println("Application Context Closed:\n\t" + actxt); } @Before public void init() throws IOException { …… userDAO = actxt.getBean("crud.hibernate.advanced.userDAO", I_UserDAO.class); System.out.println("DAO:\n\t" + userDAO); userMgrSvc = actxt.getBean("crud.hibernate.advanced.userMgrSvc", _01_UserMgrService.class); System.out.println("Service:\n\t" + userMgrSvc); } @After public void close() { …… } …… @Test public void testUserDAO_discardById() throws SQLException { …… } @Test public void testUserMgrSvc_createUser() throws SQLException { …… } …… }
<?xml version="1.0" encoding="UTF-8"?> <beans ……> …… <bean id="crud.hibernate.advanced.userMgrSvc" ……> …… </bean> <bean id="crud.hibernate.advanced.userMgrCtrl" class="tfw.integration_demo._04_spring_web_mvc._02_crud._01_basic_jdbc_crud.controller._01_UserMgrController"> <property name="userMgrSvc" ref="crud.hibernate.advanced.userMgrSvc"/> <property name="pageTitle" value="Integration&nbsp;Demo / 04&nbsp;Spring&nbsp;Web&nbsp;MVC / 02&nbsp;Create,&nbsp;Read,&nbsp;Update&nbsp;&amp;&nbsp;Discard / 04&nbsp;Hibernate&nbsp;CRUD / 02&nbsp;Advanced&nbsp;Integration / 01&nbsp;User&nbsp;Management - "/> <property name="jumpTarget"> <props> <prop key="result">/WEB-INF/pages/tfw/integration_demo/04_spring_web_mvc/02_crud/01_basic_jdbc_crud/01_user_mgr/result.jsp</prop> <prop key="detail">/WEB-INF/pages/tfw/integration_demo/04_spring_web_mvc/02_crud/01_basic_jdbc_crud/01_user_mgr/detail.jsp</prop> <prop key="login">/WEB-INF/pages/tfw/integration_demo/04_spring_web_mvc/02_crud/04_hibernate_crud/02_advanced_way/01_user_mgr/login.html</prop> <prop key="list">/WEB-INF/pages/tfw/integration_demo/04_spring_web_mvc/02_crud/01_basic_jdbc_crud/01_user_mgr/list.jsp</prop> </props> </property> </bean> </beans>
<?xml version="1.0" encoding="UTF-8"?> <beans ……> …… <bean id="crud.hibernate.basic.userMgrCtrl" ……> …… </bean> <bean id="crud.hibernate.urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/tfw/integration_demo/04_spring_web_mvc/02_crud/04_hibernate_crud/01_basic_way/01_user_mgr/action.spr">crud.hibernate.basic.userMgrCtrl</prop> <prop key="/tfw/integration_demo/04_spring_web_mvc/02_crud/04_hibernate_crud/02_advanced_way/01_user_mgr/action.spr">crud.hibernate.advanced.userMgrCtrl</prop> </props> </property> </bean> <!-- [########################################] --> <bean id="crud.hibernate.advanced.sf" ……> …… </bean> …… </beans>