JavaShuo
欄目
標籤
ssh框架整合
時間 2019-12-08
標籤
ssh
框架
整合
简体版
原文
原文鏈接
1.web.xml配置 ```xml
複製代碼
OpenSessionInViewFilter
org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
OpenSessionInViewFilter
*.action
struts2
*.jsp
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
*.action
contextConfigLocation
classpath:spring.xml
org.springframework.web.context.ContextLoaderListener
``` 2.導入所須要的jar包 ```java Struts 2: 1.commons-fileupload.jar(commons項目中的關於文件上傳的包, struts2.1.6版本後必須加入此文件)
2.commons-io.jar(commons項目(commons項目就是java中一些經常使用的公共的組件)的io子項目,是處理異常的)
3.common-annotations.jar(支持註解的包)
4.aspectjrt.jar(支持AOP的包)
5.aspectjweaver.jar(支持AOP的包)
6.cglib-nodep-2.1_3.jar(支持cglib動態代理的包) 若是用BasicDataSource來配置數據庫鏈接,還要加入2個包:
7.commons-pool.jar 8.commons-dbcp.jar hibernate 包: 1.hibernate3.jar(hibernate的核心jar包) 2.antlr-2.7.2.jar(語言轉換工具,hibernate利用它實現HQL到SQL的轉換) 3.commons-collections-3.2.1.jar(commons項目中的子項目,是對collection集合的封裝) 4.dom4j-1.6.1.jar(對dom4j的封裝,是解析xml文件的) 5.javassist-3.9.0.GA.jar(一個開源的分析、編輯和建立Java字節碼的類庫) 6.jta-1.1.jar(hibernate對事務的處理) 7.slf4j-api-1.6.4.jar(一個日誌系統的服務的api) 8.slf4j-nop-1.6.4.jar(對slf4j-api-x.x.x.jar的一個實現) 9.ojdbc14.jar (oracle驅動) 10.mysql-connector-java-5.1.6-bin.jar (mySql驅動) 若是使用註解還需添加hibernate-annotations-3.4.0.GA包: 11.hibernate-annotations.jar 12.ejb3-persistence.jar 13.hibernate-commons-annotations.jar json須要的jar包: 1.commons-beanutils-1.8.2.jar 2.commons-collections-3.2.1.jar 3.commons-lang-2.5.jar 4.commons-logging-1.1.1.jar 5.ezmorph-1.0.6.jar 6.json-lib-2.2.3-jdk15.jar 另: EL表達式:jstl.jar excel表格:jxl.jar 操做pdf文件:iText-5.0.5.jar 統計圖(JFreechart兩個):jcommon-1.0.10.jar,jfreechart-1.0.6.jar ``` 3.搭建三層架構 ```java 1.bean類 註解: @Entity @Table(name="對應的表名") 字段上加對應的註解 @Id(主鍵) @GeneratedValue(strategy=GenerationType.AUTO)(代表自增加) 也能夠寫明對應的關係,如一對一,一對多 ``` ```java 2.action層 註解:@Controller(標明action層) @ParentPackage("struts-default")(繼承的包,也能夠是json-default) @Scope("protorype")(多例) @Namespace("/")(命名空間) 寫入service類,在service類名上加上註解 @Resource 注入,寫set,get方法 在方法上加上註解 @Action(value = "方法名", results = { @Result(name = "success", location = "/main.jsp"), @Result(name = "input", location = "/login.jsp") }) ``` ```java 3.service實現層 註解:@Service 寫入dao類,在dao類名上加上註解 @Resource 注入,寫set,get方法 ``` ```java 4.dao實現層 註解:@Repository 加入 @Autowired private JdbcTemplate jdbcTemplate; 不須要寫set,get方法,能夠直接用jdbcTemplate調方法 ``` 4.建立文件jdbc.properties,spring.xml ```xml jdbc.properties: ## jdbc 鏈接配置 jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://loaclhost:3306/spring-good jdbc.user=root jdbc.password=root ## c3p0 數據源配置 c3p0.minPoolSize=15 c3p0.maxPoolSize=25 c3p0.acquireIncrement=15 c3p0.checkoutTimeout=10000 c3p0.initialPoolSize=20 c3p0.maxIdleTime=20 c3p0.idleConnectionTestPeriod=60000 spring.xml : <?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: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-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd"> <!-- 自動掃描包下的文件 --> <context:component-scan base-package="com.znsd.ssh"/> <!-- 經過context:property-placeholder加載配置文件 --> <context:property-placeholder location="classpath:jdbc.properties" /> <!-- 配置c3p0鏈接池屬性 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="com.mysql.jdbc.Driver" /> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/spring-good" /> <property name="user" value="${jdbc.user}" /> <property name="password" value="${jdbc.password}" /> <!-- 隊列中的最小鏈接數 --> <property name="minPoolSize" value="${c3p0.minPoolSize}"></property> <!-- 隊列中的最大鏈接數 --> <property name="maxPoolSize" value="${c3p0.maxPoolSize}"></property> <!-- 當鏈接耗盡時建立的鏈接數 --> <property name="acquireIncrement" value="${c3p0.acquireIncrement}"></property> <!-- 等待時間 --> <property name="checkoutTimeout" value="${c3p0.checkoutTimeout}"></property> <!-- 初始化鏈接數 --> <property name="initialPoolSize" value="${c3p0.initialPoolSize}"></property> <!-- 最大空閒時間,超出時間鏈接將被丟棄 --> <property name="maxIdleTime" value="${c3p0.maxIdleTime}"></property> <!-- 每隔60秒檢測空閒鏈接 --> <property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}"></property> </bean> <!-- session工廠由spring來管理 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <!-- 數據源配置 --> <property name="dataSource" ref="dataSource"></property> <!-- 讀取hibernate配置信息 --> <!-- <property name="configLocation" value="classpath:hibernate.cfg.xml" /> --> <!-- 自動加載映射文件 *表示匹配該文件下的全部映射文件 --> <property name="packagesToScan"> <list> <value>com.znsd.ssh.bean</value> </list> </property> <!--各類hibernate屬性 --> <property name="hibernateProperties"> <props> <!-- 方言 --> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <!-- <prop key="hibernate.current_session_context_class">thread</prop> --> <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext </prop> </props> </property> </bean> <!-- 數據源的注入 --> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 配置事務 --> <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- AOP切面攔截事務 --> <aop:config> <aop:pointcut id="serviceMethod" expression="execution(* com.znsd.ssh.service.impl.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod" /> </aop:config> <!-- 事務的通知方式 --> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <!-- read-only 事務爲只讀,通常查詢數據可把該屬性設置爲true,能夠提高效率 --> <tx:method name="find*" propagation="REQUIRED" read-only="true" /> <tx:method name="search*" propagation="REQUIRED" read-only="true" /> <tx:method name="query*" propagation="REQUIRED" read-only="true" /> <!-- propagation爲事務的傳播屬性,經常使用爲REQUIRED:若是當前線程有事務就直接使用當前事務,沒有就建立一個事務 --> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="submit*" propagation="REQUIRED" /> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="insert*" propagation="REQUIRED" /> </tx:attributes> </tx:advice> </beans> ```
不知道怎麼回事。。。
相關文章
1.
SSH框架整合
2.
SSH整合框架
3.
ssh框架整合
4.
SSH 框架整合
5.
SSH框架整合一
6.
SSH框架整合總結
7.
SSH三大框架整合
8.
idea整合SSH框架
9.
SSH框架整合案例
10.
ssh框架整合意義
更多相關文章...
•
SSH框架(Struts2+Spring+Hibernate)搭建整合詳細步驟
-
Spring教程
•
測試SSH框架分層整合及驗證事務是否有效
-
Spring教程
•
適用於PHP初學者的學習線路和建議
•
常用的分佈式事務解決方案
相關標籤/搜索
SSH框架
集合框架
框架融合
企業級框架整合
SSH三大框架
SSH框架搭建
框架
整合
JAVA集合框架
ssh
Spring教程
Hibernate教程
MyBatis教程
架構
0
分享到微博
分享到微信
分享到QQ
每日一句
每一个你不满意的现在,都有一个你没有努力的曾经。
最新文章
1.
Mud Puddles ( bfs )
2.
ReSIProcate環境搭建
3.
SNAT(IP段)和配置網絡服務、網絡會話
4.
第8章 Linux文件類型及查找命令實踐
5.
AIO介紹(八)
6.
中年轉行互聯網,原動力、計劃、行動(中)
7.
詳解如何讓自己的網站/APP/應用支持IPV6訪問,從域名解析配置到服務器配置詳細步驟完整。
8.
PHP 5 構建系統
9.
不看後悔系列!Rocket MQ 使用排查指南(附網盤鏈接)
10.
如何簡單創建虛擬機(CentoOS 6.10)
本站公眾號
歡迎關注本站公眾號,獲取更多信息
相關文章
1.
SSH框架整合
2.
SSH整合框架
3.
ssh框架整合
4.
SSH 框架整合
5.
SSH框架整合一
6.
SSH框架整合總結
7.
SSH三大框架整合
8.
idea整合SSH框架
9.
SSH框架整合案例
10.
ssh框架整合意義
>>更多相關文章<<