因為到現在還有很多朋友在通過這個例子學習SSH2入門知識,由于例子所用的框架版本太老我又沒放上jar包,很多人都是自己添加依賴,導致啟動或運行總是出現各種各樣的問題。所以大象于心不忍(>^ω^<),放下可愛的小小象,利用了一點奶孩子的時間把這個示例用Maven重新整理了下。
所有的代碼都沒動,數據庫也相同,請導入前將Maven環境配置好,唯一想說的就是 pom文件。
Hibernate
有兩種配置方式,要么用hibernate分類依賴,這個有3.3.1.GA版的,要么使用artifactId為hibernate的3.2.7版,這是因為maven倉庫里面從3.3.0.GA-3.5.4-Final的依賴包都是空的,來看實際的配置。
3.2.7的寫法
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.7.ga</version>
</dependency> <groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.1.GA</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.4.GA</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.1_3</version>
</dependency>
struts2-spring-plugin
需要將這個依賴自動引入的spring-core-2.5.3.jar、spring-beans-2.5.3.jar、spring-context-2.5.3.jar、spring-web-2.5.3.jar給去掉,不然它們會和spring-2.5.6.jar包產生沖突。
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.1.6</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
</exclusions>
</dependency>源碼下載: ssh2-maven
本文為菠蘿大象原創,如要轉載請注明出處。http://www.aygfsteel.com/bolo