JavaWeb_(SSH)三大框架整合struts+hibernate+spring_Demo
三大框架整合
一、SSH导包
二、书写Spring
三、书写Struts
四、整合Spring与Struts
五、书写(与整合)Hibernate、引入c3p0连接池并使用hibernate模板
六、整合事务
--完成用户登录
项目已上传到github 传送门
在MySQL数据库中创建spring表,添加一条假数据
一、SSH导包
导入struts的jar包
导入spring的jar包
导入hibernate的jar包
导入c3p0连接池jar包和springapo的jar包,mysql链接数据库驱动包,第四个spring整合包暂时不需要导入,下文导入的时候会说!!!
二、书写Spring
准备applicationContext.xml作为spring的配置文件
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd">
- </beans>
applicationContext.xml
编写web.xml
- <!-- 让spring随着web项目的启动而启动 -->
- <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>
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
- <display-name>SSH</display-name>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- <welcome-file>index.htm</welcome-file>
- <welcome-file>index.jsp</welcome-file>
- <welcome-file>default.html</welcome-file>
- <welcome-file>default.htm</welcome-file>
- <welcome-file>default.jsp</welcome-file>
- </welcome-file-list>
- <!-- 让spring随着web项目的启动而启动 -->
- <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>
- </web-app>
web.xml
三、配置struts
准备struts.xml配置文件
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
- "http://struts.apache.org/dtds/struts-2.5.dtd">
- <struts>
- </struts>
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
- "http://struts.apache.org/dtds/struts-2.5.dtd">
- <struts>
- </struts>
struts.xml
在web.xml中开启struts
- <!-- 让struts启动 -->
- <filter>
- <filter-name>struts</filter-name>
- <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>struts</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
- <display-name>SSH</display-name>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- <welcome-file>index.htm</welcome-file>
- <welcome-file>index.jsp</welcome-file>
- <welcome-file>default.html</welcome-file>
- <welcome-file>default.htm</welcome-file>
- <welcome-file>default.jsp</welcome-file>
- </welcome-file-list>
- <!-- 让spring随着web项目的启动而启动 -->
- <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>
- <!-- 让struts启动 -->
- <filter>
- <filter-name>struts</filter-name>
- <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>struts</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- </web-app>
web.xml
四.1、书写Action,并在struts.xml中开启动态方法调用
- package com.Gary.domain;
- public class User {
- private String id;
- private String username;
- private String password;
- public String getId() {
- return id;
- }
- public void setId(String id) {
- this.id = id;
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- }
User.java
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
- <!-- 配置包名字 -->
- <hibernate-mapping package="com.Gary.domain">
- <!-- 配置包类和数据库中的哪个表对应 -->
- <class name="User" table="user">
- <!-- 主键 -->
- <id name="id">
- <generator class="uuid"></generator>
- </id>
- <!-- 普通字段 -->
- <property name="username" column="username"></property>
- <property name="password" column="password"></property>
- </class>
- </hibernate-mapping>
User.hbm.xml
- package com.Gary.web;
- import com.Gary.domain.User;
- import com.Gary.service.UserService;
- import com.opensymphony.xwork2.ActionContext;
- import com.opensymphony.xwork2.ActionSupport;
- import com.opensymphony.xwork2.ModelDriven;
- public class UserAction extends ActionSupport implements ModelDriven<User>{
- public User user = new User();
- private UserService userService;
- public String execute() throws Exception {
- boolean success = userService.findUser(user);
- if(success)
- {
- return "toIndex";
- }else {
- ActionContext.getContext().put("error", "用户名或密码错误!!!");
- return "login";
- }
- }
- public UserService getUserService() {
- return userService;
- }
- public void setUserService(UserService userService) {
- this.userService = userService;
- }
- @Override
- public User getModel() {
- return user;
- }
- }
UserAction.java
- package com.Gary.service;
- import com.Gary.dao.UserDao;
- import com.Gary.domain.User;
- public class UserService {
- private UserDao userDao;
- public boolean findUser(User user) {
- User temp = userDao.findUser(user);
- return temp == null?false:true;
- }
- public UserDao getUserDao() {
- return userDao;
- }
- public void setUserDao(UserDao userDao) {
- this.userDao = userDao;
- }
- }
UserService.java
- package com.Gary.dao;
- import org.hibernate.Session;
- import org.hibernate.query.NativeQuery;
- import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
- import com.Gary.domain.User;
- public class UserDao extends HibernateDaoSupport {
- public User findUser(User user) {
- Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
- String sql = "select * from user where username = ? and password = ?";
- NativeQuery query = session.createSQLQuery(sql);
- query.setParameter(1,user.getUsername());
- query.setParameter(2, user.getPassword());
- query.addEntity(User.class);
- User result = (User) query.uniqueResult();
- return result;
- }
- }
UserDao.java
- <struts>
- <!-- 开启动态方法调用 -->
- <constant name="struts.devMode" value="true"></constant>
- <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
- <package name="ssh" namespace="/" extends="struts-default">
- <!-- 允许所有方法 -->
- <global-allowed-methods>regex:.*</global-allowed-methods>
- <!-- 配置Action -->
- <action name="UserAction_*" class="com.Gary.web.UserAction">
- <!-- 配置结果集第一个为转发,第二个为重定向 -->
- <result name="login">/login.jsp</result>
- <result name="toIndex" type="redirect">/index.html</result>
- </action>
- </package>
- </struts>
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
- "http://struts.apache.org/dtds/struts-2.5.dtd">
- <struts>
- <!-- 开启动态方法调用 -->
- <constant name="struts.devMode" value="true"></constant>
- <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
- <package name="ssh" namespace="/" extends="struts-default">
- <!-- 允许所有方法 -->
- <global-allowed-methods>regex:.*</global-allowed-methods>
- <!-- 配置Action -->
- <action name="UserAction_*" class="com.Gary.web.UserAction">
- <!-- 配置结果集第一个为转发,第二个为重定向 -->
- <result name="login">/login.jsp</result>
- <result name="toIndex" type="redirect">/index.html</result>
- </action>
- </package>
- </struts>
struts.xml
提交登陆<form>表单
- <form action="${pageContext.request.contextPath }/UserAction_login" method="post">
- <div class="register-box">
- <label for="username" class="username_label">
- 用 户 名
- <input maxlength="20" name="username" type="text"
- placeholder="您的用户名和登录名" />
- </label>
- <div class="tips">
- </div>
- </div>
- <div class="register-box">
- <label for="username" class="other_label">
- 密 码
- <input maxlength="20" type="password" name="password"
- placeholder="建议至少使用两种字符组合" />
- </label>
- <div class="tips">
- </div>
- </div>
- <div class="arguement">
- <input type="checkbox" id="xieyi" /> 阅读并同意
- <a href="javascript:void(0)">《你问我答用户注册协议》</a>
- <a href="register.html">没有账号,立即注册</a>
- <div class="tips" style="color: red">
- <s:property value="#error"/>
- </div>
- </div>
- <div class="submit_btn">
- <button type="submit" id="submit_btn">
- 立 即 登录
- </button>
- </div>
- </form>
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
- <%@taglib uri="/struts-tags" prefix="s" %>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <link rel="stylesheet" href="css/head.css" />
- <link rel="stylesheet" type="text/css" href="css/login.css" />
- </head>
- <body>
- <div class="dvhead">
- <div class="dvlogo"><a href="index.html">你问我答</a></div>
- <div class="dvsearch">10秒钟注册账号,找到你的同学</div>
- <div class="dvreg">
- 已有账号,立即 <a href="login.html">登录</a>
- </div>
- </div>
- <section class="sec">
- <form action="${pageContext.request.contextPath }/UserAction_login" method="post">
- <div class="register-box">
- <label for="username" class="username_label">
- 用 户 名
- <input maxlength="20" name="username" type="text"
- placeholder="您的用户名和登录名" />
- </label>
- <div class="tips">
- </div>
- </div>
- <div class="register-box">
- <label for="username" class="other_label">
- 密 码
- <input maxlength="20" type="password" name="password"
- placeholder="建议至少使用两种字符组合" />
- </label>
- <div class="tips">
- </div>
- </div>
- <div class="arguement">
- <input type="checkbox" id="xieyi" /> 阅读并同意
- <a href="javascript:void(0)">《你问我答用户注册协议》</a>
- <a href="register.html">没有账号,立即注册</a>
- <div class="tips" style="color: red">
- <s:property value="#error"/>
- </div>
- </div>
- <div class="submit_btn">
- <button type="submit" id="submit_btn">
- 立 即 登录
- </button>
- </div>
- </form>
- </section>
- <script src="js/index.js" type="text/javascript" charset="utf-8"></script>
- </body>
login.jsp
四.2、整合Spring与Struts
导入struts2-spring-plugin-2.5.16.jar整合包
在stuts.xml中让spring管理Action的创建
- <!-- 让spring管理Action的创建 -->
- <constant name="struts.objectFactory" value="spring"></constant>
在applicationContext.xml中配置web层、service层、dao层的<bean>元素
- <!-- 配置userAciton -->
- <bean name="userAction" class="com.Gary.web.UserAction" scope="prototype">
- <!-- 注入userService -->
- <property name="userService" ref="userService"></property>
- </bean>
- <!-- 配置userService -->
- <bean name="userService" class="com.Gary.service.UserService">
- <!-- 注入userDao -->
- <property name="userDao" ref="userDao"></property>
- </bean>
- <!-- 配置userDao -->
- <bean name="userDao" class="com.Gary.dao.UserDao">
- <!-- 注入sessionFactory (用到了HibernateDaoSupport) -->
- <property name="sessionFactory" ref="sessionFactory"></property>
- </bean>
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd">
- <!-- 配置userAciton -->
- <bean name="userAction" class="com.Gary.web.UserAction" scope="prototype">
- <!-- 注入userService -->
- <property name="userService" ref="userService"></property>
- </bean>
- <!-- 配置userService -->
- <bean name="userService" class="com.Gary.service.UserService">
- <!-- 注入userDao -->
- <property name="userDao" ref="userDao"></property>
- </bean>
- <!-- 配置userDao -->
- <bean name="userDao" class="com.Gary.dao.UserDao">
- <!-- 注入sessionFactory (用到了HibernateDaoSupport) -->
- <property name="sessionFactory" ref="sessionFactory"></property>
- </bean>
- </beans>
applicationContext.xml
五、整合Hibernate、引入连接池并使用hibernate模板
在applicationContext.xml中整合Hibernate
- <bean name="dataSource"
- class="com.mchange.v2.c3p0.ComboPooledDataSource">
- <property name="jdbcUrl" value="jdbc:mysql:///spring"></property>
- <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
- <property name="user" value="root"></property>
- <property name="password" value="123456"></property>
- </bean>
- <!-- 配置sesisonFactory -->
- <bean name="sessionFactory"
- class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
- <!-- 配置dataSource -->
- <property name="dataSource" ref="dataSource"></property>
- <!-- 配置基本属性 -->
- <property name="hibernateProperties">
- <props>
- <!-- 方言 -->
- <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
- <!-- 生成表策略 -->
- <prop key="hibernate.hbm2ddl.auto">update</prop>
- <!-- 是否生成sql语句 -->
- <prop key="hibernate.show_sql">true</prop>
- <!-- 是否格式化sql -->
- <prop key="hibernate.format_sql">true</prop>
- </props>
- </property>
- <!-- 读取orm元数据 -->
- <property name="mappingDirectoryLocations"
- value="classpath:com/Gary/domain"></property>
- </bean>
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd">
- <bean name="dataSource"
- class="com.mchange.v2.c3p0.ComboPooledDataSource">
- <property name="jdbcUrl" value="jdbc:mysql:///spring"></property>
- <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
- <property name="user" value="root"></property>
- <property name="password" value="123456"></property>
- </bean>
- <!-- 配置sesisonFactory -->
- <bean name="sessionFactory"
- class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
- <!-- 配置dataSource -->
- <property name="dataSource" ref="dataSource"></property>
- <!-- 配置基本属性 -->
- <property name="hibernateProperties">
- <props>
- <!-- 方言 -->
- <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
- <!-- 生成表策略 -->
- <prop key="hibernate.hbm2ddl.auto">update</prop>
- <!-- 是否生成sql语句 -->
- <prop key="hibernate.show_sql">true</prop>
- <!-- 是否格式化sql -->
- <prop key="hibernate.format_sql">true</prop>
- </props>
- </property>
- <!-- 读取orm元数据 -->
- <property name="mappingDirectoryLocations"
- value="classpath:com/Gary/domain"></property>
- </bean>
- <!-- 配置userAciton -->
- <bean name="userAction" class="com.Gary.web.UserAction" scope="prototype">
- <!-- 注入userService -->
- <property name="userService" ref="userService"></property>
- </bean>
- <!-- 配置userService -->
- <bean name="userService" class="com.Gary.service.UserService">
- <!-- 注入userDao -->
- <property name="userDao" ref="userDao"></property>
- </bean>
- <!-- 配置userDao -->
- <bean name="userDao" class="com.Gary.dao.UserDao">
- <!-- 注入sessionFactory (用到了HibernateDaoSupport) -->
- <property name="sessionFactory" ref="sessionFactory"></property>
- </bean>
- </beans>
applicationContext.xml
在web.xml中扩大session范围【扩大session范围<filter>一定要放在启动struts上】
- <!-- 扩大session范围 -->
- <filter>
- <filter-name>openSessionInView</filter-name>
- <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>openSessionInView</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
- <display-name>SSH</display-name>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- <welcome-file>index.htm</welcome-file>
- <welcome-file>index.jsp</welcome-file>
- <welcome-file>default.html</welcome-file>
- <welcome-file>default.htm</welcome-file>
- <welcome-file>default.jsp</welcome-file>
- </welcome-file-list>
- <!-- 让spring随着web项目的启动而启动 -->
- <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>
- <!-- 扩大session范围 -->
- <filter>
- <filter-name>openSessionInView</filter-name>
- <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>openSessionInView</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <!-- 让struts启动 -->
- <filter>
- <filter-name>struts</filter-name>
- <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>struts</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- </web-app>
web.xml
六、整合事务
在applicationContext.xml中配置事务
- <!-- 事务的核心管理器 -->
- <bean name="transactionManager"
- class="org.springframework.orm.hibernate5.HibernateTransactionManager">
- <!-- 需要sessionFactory -->
- <property name="sessionFactory" ref="sessionFactory"></property>
- </bean>
- <!-- 通知 -->
- <tx:advice id="advice"
- transaction-manager="transactionManager">
- <tx:attributes>
- <tx:method name="*" />
- </tx:attributes>
- </tx:advice>
- <!-- 织入 -->
- <aop:config>
- <!-- 切入点 -->
- <aop:pointcut
- expression="execution(* com.Gary.service.*.*(..))" id="pc" />
- <!-- 配置切面 -->
- <aop:advisor advice-ref="advice" pointcut-ref="pc" />
- </aop:config>
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd">
- <bean name="dataSource"
- class="com.mchange.v2.c3p0.ComboPooledDataSource">
- <property name="jdbcUrl" value="jdbc:mysql:///spring"></property>
- <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
- <property name="user" value="root"></property>
- <property name="password" value="123456"></property>
- </bean>
- <!-- 配置sesisonFactory -->
- <bean name="sessionFactory"
- class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
- <!-- 配置dataSource -->
- <property name="dataSource" ref="dataSource"></property>
- <!-- 配置基本属性 -->
- <property name="hibernateProperties">
- <props>
- <!-- 方言 -->
- <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
- <!-- 生成表策略 -->
- <prop key="hibernate.hbm2ddl.auto">update</prop>
- <!-- 是否生成sql语句 -->
- <prop key="hibernate.show_sql">true</prop>
- <!-- 是否格式化sql -->
- <prop key="hibernate.format_sql">true</prop>
- </props>
- </property>
- <!-- 读取orm元数据 -->
- <property name="mappingDirectoryLocations"
- value="classpath:com/Gary/domain"></property>
- </bean>
- <!-- 事务的核心管理器 -->
- <bean name="transactionManager"
- class="org.springframework.orm.hibernate5.HibernateTransactionManager">
- <!-- 需要sessionFactory -->
- <property name="sessionFactory" ref="sessionFactory"></property>
- </bean>
- <!-- 通知 -->
- <tx:advice id="advice"
- transaction-manager="transactionManager">
- <tx:attributes>
- <tx:method name="*" />
- </tx:attributes>
- </tx:advice>
- <!-- 织入 -->
- <aop:config>
- <!-- 切入点 -->
- <aop:pointcut
- expression="execution(* com.Gary.service.*.*(..))" id="pc" />
- <!-- 配置切面 -->
- <aop:advisor advice-ref="advice" pointcut-ref="pc" />
- </aop:config>
- <!-- 配置userAciton -->
- <bean name="userAction" class="com.Gary.web.UserAction" scope="prototype">
- <!-- 注入userService -->
- <property name="userService" ref="userService"></property>
- </bean>
- <!-- 配置userService -->
- <bean name="userService" class="com.Gary.service.UserService">
- <!-- 注入userDao -->
- <property name="userDao" ref="userDao"></property>
- </bean>
- <!-- 配置userDao -->
- <bean name="userDao" class="com.Gary.dao.UserDao">
- <!-- 注入sessionFactory (用到了HibernateDaoSupport) -->
- <property name="sessionFactory" ref="sessionFactory"></property>
- </bean>
- </beans>
applicationContext.xml
JavaWeb_(SSH)三大框架整合struts+hibernate+spring_Demo的更多相关文章
- Maven SSH三大框架整合的加载流程
<Maven精品教程视频\day02视频\03ssh配置文件加载过程.avi;> 此课程中讲 SSH三大框架整合的加载流程,还可以,初步接触的朋友可以听一听. < \day02视频\ ...
- 三大框架:Struts+Hibernate+Spring
三大框架:Struts+Hibernate+Spring Java三大框架主要用来做WEN应用. Struts主要负责表示层的显示 Spring利用它的IOC和AOP来处理控制业务(负责对数据库的操作 ...
- SSH三大框架整合案例
SSH三大框架的整合 SSH三个框架的知识点 一.Hibernate框架 1. Hibernate的核心配置文件 1.1 数据库信息.连接池配置 1.2 Hibernate信息 1.3 映射配置 ...
- SSH三大框架整合配置详解
首先,三大框架整合,肯定是要导入相当多的jar包,这是不容置疑的! 这里就不一一列举了,直接截图吧: (1) 基于配置文件的整合: 第一步:我们需要在we ...
- 关于ssh三大框架整合的碎碎念
三大框架整合,无非就是一个导jar包,修改配置文件的过程.完了就没事了. 还是有很多细节性的问题 比如在spring中写applicationContext.xml文件时不提示: 解决方法如下: 如果 ...
- SSH 三大框架整合
Spring整合web项目 在Servlet当中直接加载配置文件,获取对象 存在问题 每次请求都会创建一个Spring的工厂,这样浪费服务器资源,应该一个项目只有一个Spring的工厂. 在服务器启动 ...
- 2018.11.11 Java的 三大框架:Struts+Hibernate+Spring
·定义:Java三大框架主要用来做WEN应用.Struts主要负责表示层的显示: Spring利用它的IOC和AOP来处理控制业务(负责对数据库的操作): Hibernate主要是数据持久化到数据库. ...
- SSH三大框架整合配置详细步骤(3)
5 配置Spring2.5 5.1 基础配置 1) 导入spring包.下载spring-framework-2.5.6并解压后,在spring-framework-2.5.6" ...
- JAVAEE——SSH三大框架整合(spring+struts2+hibernate)
一.整合原理 二.导包(41个) 1.hibernate (1)hibernate/lib/required (2)hibernate/lib/jpa | java persist api java的 ...
随机推荐
- MySQL 聚合函数(二)Group By的修饰符——ROLLUP
原文为MySQL 5.7 官方手册:12.20.2 GROUP BY Modifiers 一.ROLLUP 修饰符的意义 GROUP BY子句允许添加WITH ROLLUP修饰符,该修饰符可以对分组后 ...
- select into from与insert into select区别
创建一个table2 向table2中插入 table1中name为11的所有行(前提table2不存在) select * into table2 from table1 where name=‘ ...
- hdu 1506 最大子矩阵面积
//写动态规划的题目 要把主要问题提炼出来 这里的问题就是求area=(j-k+1)*a[i] 如果找到j k是解决这个题目的关键 这里暴力求肯定是要超时的 这里用dp来优化 #include< ...
- hdu 2821 学习一点dfs的小技巧吧。。 还是自己太弱了
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int r,c ...
- WindowsAPI操作串口
#include <windows.h> #include <stdio.h> int main() { //1.打开串口 HANDLE hCom; hCom = Create ...
- 2.3 使用 dom4j 对 xml文件进行 dom 解析
// 使用dom4j对XML文档进行解析 CRUD public class Demo1 { //读取XML文档中第二本书的书名 <书名>javaWEB</书名> @Test ...
- debian设置limits.conf
最近已经把自己的游戏框架主要功能完成得差不多了,决定将自己的开发环境从debian7升级到debian9,不然太多第三方依赖都跟不上了.debian10刚出来,MongoDB还没适配,所以暂不考虑. ...
- 三次样条插值 cubic spline interpolation
什么是三次样条插值 插值(interpolation)是在已知部分数据节点(knots)的情况下,求解经过这些已知点的曲线, 然后根据得到的曲线进行未知位置点函数值预测的方法(未知点在上述已知点自变量 ...
- Linux基础篇之FTP服务器搭建(二)
上一篇文章说到了搭建FTP匿名用户的访问,接下来讲解一下本地用户的登录. 一.首先先建立一个用户,这里举例:xiaoming,并为其设置密码. 二.修改配置文件. 文件:ftpusers 文件:us ...
- eclipse设置打开java文件目录
1. 第一步: 2. 第二步: 3. 第三步: Location:C:/WINDOWS/explorer.exe Arguments:${container_loc}