ssh整合步骤
这几天打算深入学习ssh,这里总结了ssh整合的基本步骤,
ssh整合步骤:
1.导入必要的jar包;
2.在web.xml中配置对spring的支持;
在web.xml中加入如下代码.
<!-- Spring 载入上下文监听器 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:application-context.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
<?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:aop="http://www.springframework.org/schema/aop" 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-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"></beans>
<bean id="dataSource" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/ssh?createDatabaseIfNotExist=true" /> <property name="username" value="root" /> <property name="password" value="sql" /> <property name="defaultAutoCommit" value="true" /> <property name="maxActive" value="100" /> <property name="initialSize" value="5" /> <property name="maxWait" value="1000" /> <property name="maxIdle" value="20" /> <property name="minIdle" value="3" /> <property name="removeAbandoned" value="true" /> <property name="removeAbandonedTimeout" value="180" /> </bean>
<bean id="sessionFactory" ref="dataSource" /> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.show_sql=true hibernate.format_sql=true </value> </property> <!-- 扫描hibernate hbm.xml文件 --> <property name="mappingResources"><list><value>*.hbm.xml</value></list></property> </bean>
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="com.cw.x2.auth.common.resac.entity"> <class name="Org" table="`Org`"> <id name="code" type="java.lang.String"> <column name="`code`" length="36" /> <generator /> </id> <property name="name" type="java.lang.String"> <column name="`name`" length="100" not-null="true" /> </property> <property name="certType" type="java.lang.String"> <column name="`certType`" length="4" /> </property> <property name="sponsor" type="java.lang.String"> <column name="`sponsor`" length="32" /> </property> <property name="country" type="java.lang.String"> <column name="`country`" length="3" /> </property> </class></hibernate-mapping>
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"><struts> <package name="" extends="struts-default" namespace="/"> <action name="" method=""> <result name="success">/index.jsp</result> </action> </package></struts>
<!-- struts2 action 分发依赖的过滤器 --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping>
<!-- struts2委托spring管理 --> <constant name="struts.objectFactory" value="spring" />
<bean id="test" ref="dataSource" /> </bean> <bean id="testAction" scope="prototype"> <property name="test" ref="test"/> </bean>