黄色网址大全免费-黄色网址你懂得-黄色网址你懂的-黄色网址有那些-免费超爽视频-免费大片黄国产在线观看

專注Java教育14年 全國咨詢/投訴熱線:400-8080-105
動(dòng)力節(jié)點(diǎn)LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 hot資訊 SSH框架搭建詳細(xì)步驟

SSH框架搭建詳細(xì)步驟

更新時(shí)間:2022-10-21 10:25:41 來源:動(dòng)力節(jié)點(diǎn) 瀏覽1250次

相信大家對(duì)SSH框架原理已經(jīng)有所了解,SSH框架配置時(shí)這幾個(gè)文件比較重要:Spring,Struts2,hibernate,web.xml。

SSH框架配置第一步:jar包加載

開始配置前只要把SSH需要的所有jar復(fù)制到WebRoot下的WEB-INF中的lib目錄下。這里已經(jīng)整合好的所有jar包,下載地址:點(diǎn)擊打開鏈接用這種方法的優(yōu)點(diǎn)是:既可以在myeclipse用也可以在eclipse中使用,不會(huì)出現(xiàn)jar包沖突的事情。

SSH框架配置第二步:hibernate配置

hibernate.cfg.xml文件配置

<span style="font-size:14px;"><?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
	<session-factory>
		<!-- 配置Hibernate的基本屬性 -->
		<!-- 1. 數(shù)據(jù)源配置到 IOC 容器中, 在這里不需再配置 -->
		<!-- 2. 關(guān)聯(lián)的 .hbm.xml 也在 IOC 容器 配置 SessionFactory 實(shí)例時(shí) 進(jìn)行配置 -->
		<!-- 3. 配置 Hibernate 的基本屬性: 方言, SQL 顯示及格式化, 生成數(shù)據(jù)表的策略以及 二級(jí)緩存 -->
		<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
		<property name="hibernate.show_sql">true</property>
		<property name="hibernate.format_sql">false</property>
		<property name="hibernate.hbm2ddl.auto">update</property>
		<property name="hibernate.temp.use_jdbc_metadata_defaults">fals </property>		
		<!-- 配置 Hibernate 二級(jí)緩存相關(guān)屬性 -->
	</session-factory>
</hibernate-configuration>
</span>

db.properties文件配置

<span style="font-size:14px;">jdbc.user=root
jdbc.password=220316
jdbc.jdbcUrl=jdbc:mysql://127.0.0.1:3306
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.initPoolSize=5
jdbc.maxPoolSize=10</span>

這里和傳統(tǒng)的SSH配置不一樣,目前主流的是把hibernate中關(guān)于數(shù)據(jù)庫的相關(guān)配置信息給分離到db.properties文件配置中去。

這樣做的好處是后期維護(hù)比較方法,代碼比較簡潔不容易出錯(cuò)。

SSH框架配置第三步:Spring配置

applicationContext.xml文件配置

<span style="font-size:14px;"><?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:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
	<context:component-scan base-package="com.ge"></context:component-scan>
	<!-- 導(dǎo)入外部資源文件 -->
	<context:property-placeholder location="classpath:db.properties" />
	<!-- c3p0方式配置數(shù)據(jù)源 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="user" value="${jdbc.user}"></property>
		<property name="password" value="${jdbc.password}"></property>
		<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
		<property name="driverClass" value="${jdbc.driverClass}"></property>

		<property name="initialPoolSize" value="${jdbc.initPoolSize}"></property>
		<property name="maxPoolSize" value="${jdbc.maxPoolSize}"></property>
	</bean>
	<!-- 配置Hibernate的SessionFactory實(shí)例: 通過 Spring 提供的 LocalSessionFactoryBean 
		進(jìn)行配置 -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
		<!-- 配置數(shù)據(jù)源屬性 -->
		<property name="dataSource" ref="dataSource"></property>
		<!-- 配置 Hibernate 配置文件位置 和 名稱 -->
		<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
		<!-- 配置 Hibernate 映射文件的位置和名稱, 可以使用通配符 -->
		<property name="mappingLocations" value="classpath:com/ge/entity/*.hbm.xml"></property>
	</bean>
	<!-- 1. 配置Hibernate事務(wù)管理器 -->
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate5.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<!-- 2. 配置事務(wù)屬性, 需要事務(wù)管理器 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="get*" read-only="true"/>
			<tx:method name="*"/>
		</tx:attributes>
	</tx:advice>
	<!-- 3. 配置事務(wù)切點(diǎn) -->
	<aop:config>
		<aop:pointcut expression="execution( * com.ge.biz.imp.*.*(..))" id="txPointcut"/>
		<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
	</aop:config>
	
</beans>
</span>

這里需要改的是:

1.映射文件的位置和名字,因?yàn)槲覝y(cè)試用的是,這里需要修改的是:com/ge/entity也就是你映射文件所在的包位置。

2.還有就是配置事務(wù)切點(diǎn)的位置,我這里的位置是:,這里需要修改的是事務(wù)切點(diǎn)位置:com.ge.biz.imp也就是你biz層所在位置。

applicationContext-beans.xml文件配置

<span style="font-size:14px;"><?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:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">	
	<bean class="com.ge.dao.imp.EquipmentDaoImp" id="EquipmentDaoImp">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean class="com.ge.biz.imp.EquipmentBizImp" id="EquipmentBizImp">
		<property name="equipmentDao" ref="EquipmentDaoImp"></property>
	</bean>
	<bean class="com.ge.action.TestAction" id="testAction" scope="prototype">
		<property name="equipmentBiz" ref="EquipmentBizImp"></property>
	</bean>
</beans>
</span>

applicationContext-beans.xml文件配置配置的重點(diǎn)是:

<bean class="com.ge.dao.imp.EquipmentDaoImp" id="EquipmentDaoImp">
              <property name="sessionFactory" ref="sessionFactory"></property>
</bean>

就是dao層中會(huì)話工廠的配置,這個(gè)如果不配置那hibernate的功能就都用不了了。

SSH框架配置第四步:Struts2配置

Struts2文件配置

<span style="font-size:14px;"><?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
	<constant name="struts.enable.DynamicMethodInvocation" value="false" />
	<constant name="struts.multipart.saveDir" value="C:/repository"/>  
	<constant name="struts.devMode" value="true" />
	<package name="HY" namespace="/" extends="struts-default">
		<action name="testAction" class="testAction">
			<result name="index">index.jsp</result>
			<result name="success">welcome.jsp</result>
			<result name="fail">fail.jsp</result>
		</action>
	</package>
</struts>
</span>

Struts2中沒有什么難點(diǎn),一般配置出錯(cuò)都不在這里。

SSH框架配置第五步:web.xml配置

<span style="font-size:14px;"><?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.1"
	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">
	<!-- 配置 Spring 配置文件的名稱和位置 -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext*.xml</param-value>
	</context-param>	
	<!-- 啟動(dòng) IOC 容器的 ServletContextListener -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<!-- struts2配置 -->
	<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>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
</web-app></span>

web.xml配置配置非常關(guān)鍵,如果配置出錯(cuò),tomcat啟動(dòng)都啟動(dòng)不了。如果大家對(duì)此比較感興趣,想了解更多相關(guān)知識(shí),可以關(guān)注一下動(dòng)力節(jié)點(diǎn)的SSH整合視頻教程,里面有更豐富的知識(shí)等著大家去學(xué)習(xí),希望對(duì)大家能夠有所幫助。

提交申請(qǐng)后,顧問老師會(huì)電話與您溝通安排學(xué)習(xí)

免費(fèi)課程推薦 >>
技術(shù)文檔推薦 >>
主站蜘蛛池模板: 中国护士一级毛片免费版本 | 深夜男人天堂 | 五月天毛片 | 欧美在线观看免费一区视频 | 永久免费看毛片 | 狠狠插入视频 | 一区二区三区欧美日韩 | 免费观看一级一片 | 久久制服丝袜 | 91在线精品亚洲一区二区 | aaa在线观看视频高清视频 | 制服丝袜中文字幕在线观看 | 我要看黄色一级毛片 | 男人下面进女人下面视频免费 | 欧美日韩中文一区二区三区 | 黑人黄色毛片 | 丁香六月在线 | 成年人网站在线观看免费 | 日本三级黄在线观看 | 涩在线| www.激情五月| 在线午夜| 亚洲第一在线播放 | 精品国产乱码一区二区三区 | sss欧美 | 手机免费在线看毛片 | 爱操视频在线观看 | 暗香影院午夜片 | 婷婷在线五月 | 看黄网页 | 看国产一级片 | 久久国产一级毛片一区二区 | 在线观看视频色 | 欧美日韩亚洲第一页 | 精品一区二区三区的国产在线观看 | 天天影视色香欲综合网网站麻豆 | 亚洲成熟中老妇女 | 韩国视频在线 | 国产精品手机视频一区二区 | 狠狠躁夜夜躁人人躁婷婷视频 | 亚州激情 |