ssh三大框架整合
(1)struts2
(2)hibernate5.x
(3)spring4.x
ssh框架整合的思想:
web层:struts
|
V
service层(业务逻辑层):spring
|
V
dao层(数据层):hibernate,对数据库进行crud操作
俩个框架整合##:
1.struts和spring整合:
把struts的action对象创建交给spring进行管理
2.spring和hibernat整合:
把hibernate核心配置文件里面的数据库的配置,直接写在spring配置文件中
第一次访问的时候很慢,因为第一次访问的时候创建sessionFactory对象
把sessionFactory对象创建交给spring管理
在服务器启动的时候创建sessionFactory对象
1.把struts2的action交给spring管理
package cn.itcast.action;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
@Override
public String execute() throws Exception {
System.out.println("action.......");
return NONE;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd" >
<struts>
<package name="demo1" extends="struts-default" namespace="/">
<action name="userAction" class="userAction"></action>
</package>
</struts>
<?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">
<!-- 配置c3p0连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!--注入里面的属性值 -->
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="user" value="root"></property>
<property name="jdbcUrl" value="jdbc:mysql:///spring_day04"></property>
<property name="password" value="123456"></property>
</bean>
<!--配置action对象 -->
<bean id="userAction" class="cn.itcast.action.UserAction" scope="prototype"></bean>
</beans>
<?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" version="3.1">
<display-name>spring_day04_sshdemo1</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:bean1.xml</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<!-- 注意你的配置,2.5版本直接是filter,不是ng.filter -->
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>
</web-app>