SSH simple integration


struts to implement the interaction between browser and server;

spring completes object creation, object dependency and transaction processing

hibernate completes data access

Difficult points:

1. By accessing the browser, spring can create an action without creating it by itself

2. Set c3p0 in spring to improve performance.

3. The XML file reference file contains error causes tomcat to fail to start

Solution: in Preferences > XML file > validation > XML, the check mark before "hour all XML schema locations" is removed. It will disable validation that points to the same namespace reference at different schema locations, only as a result of the first found verifiable XML file.


web.xml configuration:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="" xmlns="" xsi:schemaLocation="" id="WebApp_ID" version="3.1">
	<!-- To configure spring Of OpenSessionInView Mode [Purpose: JSp Page access lazy loading data] -->
	<!-- struts2 To configure -->

	<!-- Spring To configure -->


Public bean.xml configuration:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

	<!-- 1) Connection pool instance -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
		<property name="jdbcUrl" value="jdbc:mysql:///day16"></property>
		<property name="user" value="root"></property>
		<property name="password" value="root"></property>
		<property name="initialPoolSize" value="3"></property>
		<property name="maxPoolSize" value="6"></property>

	<!-- 2) SessionFactory Instance creation -->
	<!-- All configurations are configured by spring Maintain(Not required in project hibernate.cfg.xml La) -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<!-- a. Connection pool -->
		<property name="dataSource" ref="dataSource"></property>
		<!-- b. hibernate Common configuration: dialect, display sql,Automatic table building, etc -->
		<property name="hibernateProperties">
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="">update</prop>
		<!-- c. Mapping configuration -->
		<property name="mappingLocations">
	<!-- 3) Transaction configuration -->
	<!-- # Transaction manager -- >
	<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	<!-- # Transaction enhancement -- >
	<tx:advice id="txAdvice" transaction-manager="txManager">
			<tx:method name="*" read-only="false"/>
	<!-- # AOP configuration -- >
		<aop:pointcut expression="execution(* SSH.*.*(..))" id="pt"/>
		<aop:advisor advice-ref="txAdvice" pointcut-ref="pt"/>


    <bean id = "adminDao" class="SSH.AdminDao">
       <property name="sf" ref="sessionFactory"></property>

dao layer code:

package SSH;

import org.hibernate.SessionFactory;

public class AdminDao {
    private SessionFactory sf;
    public void setSf(SessionFactory sf) {
		this.sf = sf;
    public Admin query(int id){
    	Admin admin = (Admin) sf.getCurrentSession().get(Admin.class, id);
    	return admin;

Action code:

package SSH;

import org.apache.struts2.ServletActionContext;

public class AdminAction {
   private AdminService service;
   public void setService(AdminService service) {
	this.service = service;
   public String query(){
	   int id = 2;
	   Admin admin = service.query(id);
	   ServletActionContext.getRequest().setAttribute("admin", admin);
	   return "success";


Tags: xml Spring Hibernate ssh

Posted on Fri, 10 Jan 2020 11:07:04 -0500 by bfinucan