下载地址:源码和详细搭建步骤
使用myeclipse2014搭建ssh框架
- 1. spring搭建
- 2. struts2搭建
- 3. hibernate搭建
- 4. applicationContext编写
- 5. web.xml编写
1. spring搭建
-
创建一个javaweb项目
-
导入spring框架
-
最高版本3.1支持
4. 选择类库
spring导入完毕
2. struts2搭建
3. hibernate搭建
选择数据驱动
4. applicationContext编写
<?xml version="1.0" encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"><!-- 注解ioc扫描 --><context:component-scan base-package="com.test" /><!-- <bean id="dataSource"class="org.apache.commons.dbcp.BasicDataSource"><property name="url"value="jdbc:mysql://localhost:3306/ssh_study"></property><property name="username" value="root"></property><property name="password" value="123456"></property></bean> --><!-- ComboPooledDataSource数据源配置 --><bean id="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value="com.mysql.jdbc.Driver"></property><property name="jdbcUrl"value="jdbc:mysql://localhost:3306/ssh_study"></property><property name="user" value="root"></property><property name="password" value="123456"></property></bean><!-- session工厂 --><bean id="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><property name="dataSource"><ref bean="dataSource" /></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><!-- 展示sql --><prop key="hibernate.show_sql">true</prop><prop key="hibernate.format_sql">true</prop></props></property><property name="mappingResources"><list><value>com/test/entity/Users.hbm.xml</value></list></property></bean><!-- hibernate 模板 用来操作数据库 --><bean class="org.springframework.orm.hibernate3.HibernateTemplate"><property name="sessionFactory" ref="sessionFactory" /></bean><!-- 声明式事务管理器 --><bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory" /></bean><!-- 事务注解驱动 --><tx:annotation-driven transaction-manager="transactionManager"/><!-- action --><bean id="userAction" class="com.test.action.UserAction" scope="prototype"></bean></beans>
5. web.xml编写
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"><display-name>ssh01</display-name><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><!-- 新增配置 openSessionViewFilter session的开关给它管理 --><filter><filter-name>openSessionInViewFilter</filter-name><filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class></filter><filter-mapping><filter-name>openSessionInViewFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping>
</web-app>