Spring4.03+Hibernate4.3.5整合

通过maven工具进行构建:

第一步:

 


Spring4.03+Hibernate4.3.5整合_第1张图片
 第二步:

 
Spring4.03+Hibernate4.3.5整合_第2张图片
 

 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <!--项目的全球唯一标识符,通常使用全限定的包名区分该项目和其他项目。
  并且构建时生成的路径也是由此生成, 如com.mycompany.app生成的相对路径为:/com/mycompany/app-->
  <groupId>huihai.maven.example</groupId>
  <artifactId>mvc-hibernate4</artifactId>
  <!-- 此项目输出的artifact的类型 -->
  <packaging>war</packaging>
  <!--项目当前版本,格式为:主版本.次版本.增量版本-限定版本号-->
  <version>0.0.1-SNAPSHOT</version>
  <!--项目的名称, Maven产生的文档用-->
  <name>HuiHaiSpringMVC</name>
  <!--项目主页的URL, Maven产生的文档用-->
  <url>http://127.0.0.1/hhapp</url>
  <properties>
  <java-version>1.7</java-version>
  <org.springframework-version>4.0.3.RELEASE</org.springframework-version>
  <org.aspectj-version>1.7.4</org.aspectj-version>
  <org.slf4j-version>1.6.4</org.slf4j-version>
  <jackson-version>1.9.0</jackson-version>
  <hibernate-version>4.3.5.Final</hibernate-version>
  <querydsl.version>2.9.0</querydsl.version>
  </properties>
  <!-- 此项目的所有依赖项列表 -->
  <dependencies> 
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>   
   
    <!-- servlet/jsp api -->
    <dependency>
         <groupId>javax.servlet</groupId>
         <artifactId>servlet-api</artifactId>
         <version>2.5</version>
         <scope>provided</scope>
     </dependency>
     <dependency>
         <groupId>javax.servlet.jsp</groupId>
         <artifactId>jsp-api</artifactId>
         <version>2.1</version>
         <scope>provided</scope>
     </dependency>
    
     <!-- jstl -->
     <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
   
   
    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
   
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>   
   
    <!-- spring需要的aspectj依赖包 -->
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>${org.aspectj-version}</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>${org.aspectj-version}</version>
    </dependency> 
   
    <!-- Mysql -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.29</version>
    </dependency>
   
     <!-- Hibernate4 -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${hibernate-version}</version>
    </dependency>
    <!-- for JPA, use hibernate-entitymanager instead of hibernate-core -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${hibernate-version}</version>
    </dependency>
    <!-- 以下可选 -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-envers</artifactId>
        <version>${hibernate-version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
        <version>${hibernate-version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-proxool</artifactId>
        <version>${hibernate-version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-infinispan</artifactId>
        <version>${hibernate-version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-ehcache</artifactId>
        <version>${hibernate-version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.common</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>4.0.4.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss</groupId>
        <artifactId>jandex</artifactId>
        <version>1.1.0.Final</version>
    </dependency>
           
   
    <!-- 为了让Hibernate使用代理模式,需要javassist -->
    <dependency>
       <groupId>org.javassist</groupId>
       <artifactId>javassist</artifactId>
       <version>3.18.1-GA</version>
    </dependency>
   
    <dependency>
        <groupId>org.jboss.logging</groupId>
        <artifactId>jboss-logging</artifactId>
        <version>3.1.3.GA</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.spec.javax.annotation</groupId>
        <artifactId>jboss-annotations-api_1.2_spec</artifactId>
        <version>1.0.0.Final</version>
    </dependency>
           
   
    <dependency>
        <groupId>antlr</groupId>
        <artifactId>antlr</artifactId>
        <version>2.7.7</version>
    </dependency>
    <dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
    </dependency>
   
   
    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.1</version>
    </dependency>
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>commons-pool</groupId>
        <artifactId>commons-pool</artifactId>
        <version>1.4</version>
    </dependency>
           
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>
      
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>
   
    <!-- tomcat7.0.35 数据库连接池 -->
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-dbcp</artifactId>
        <version>7.0.35</version>
    </dependency>  
 
   
    <!-- fileupload -->
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.2.2</version>
    </dependency>
    <!-- io -->
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
    </dependency> 
   
    <!-- Logging -->
 <dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>${org.slf4j-version}</version>
 </dependency>
 <dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>jcl-over-slf4j</artifactId>
  <version>${org.slf4j-version}</version>
  <scope>runtime</scope>
 </dependency>
 <dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>${org.slf4j-version}</version>
  <scope>runtime</scope>
 </dependency>
 
 <!-- jackson -->
 <dependency>
  <groupId>org.codehaus.jackson</groupId>
  <artifactId>jackson-core-asl</artifactId>
  <version>${jackson-version}</version>
 </dependency>
 <dependency>
  <groupId>org.codehaus.jackson</groupId>
  <artifactId>jackson-mapper-asl</artifactId>
  <version>${jackson-version}</version>
 </dependency>
 
 <!-- google gson -->
 <dependency>
  <groupId>com.google.code.gson</groupId>
  <artifactId>gson</artifactId>
  <version>2.2.4</version>
 </dependency>
 <dependency>
  <groupId>com.alibaba</groupId>
  <artifactId>fastjson</artifactId>
  <version>1.1.38</version>
 </dependency>
 
 <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>16.0.1</version>
    </dependency>
    <dependency> 
      <groupId>net.sourceforge.pinyin4j</groupId> 
      <artifactId>pinyin4j</artifactId> 
      <version>2.5.0</version>
    </dependency>  
   <!-- sql server数据库驱动 <dependency> <groupId>net.sourceforge.jtds</groupId>
   <artifactId>jtds</artifactId> <version>1.3.0</version> </dependency> -->
   <!-- oracle数据库驱动:maven仓库中的ojdbc下载需要oracle的官方授权,先在网上找一个ojdbc14.jar包,上传到本地的maven仓库
       mvn install:install-file -Dfile=D:/resources/ojdbc/ojdbc14.jar -DgroupId=com.oracle
       -DartifactId=ojdbc14 -Dversion=10.2.0.1.0 -Dpackaging=jar <dependency> <groupId>com.oracle</groupId>
       <artifactId>ojdbc14</artifactId> <version>10.2.0.4.0</version> </dependency> -->
 
 
    <!-- struts2 <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId>
        <version>${struts.version}</version> <exclusions> <exclusion> <artifactId>javassist</artifactId>
        <groupId>javassist</groupId> </exclusion> </exclusions> </dependency> <dependency>
        <groupId>org.apache.struts</groupId> <artifactId>struts2-spring-plugin</artifactId>
        <version>${struts.version}</version> <exclusions> <exclusion> <artifactId>spring-core</artifactId>
        <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> -->
  
  </dependencies>
  <build>
    <finalName>mvc-hibernate4</finalName>
  </build>
</project>

 

处理官网没有的jar包

 

maven向本地仓库导入jar包(处理官网没有的jar包)

对于官网没有的jar包,maven向本地仓库导入jar包用如下命令

mvn install:install-file
-DgroupId=包名
-DartifactId=项目名
-Dversion=版本号
-Dpackaging=jar
-Dfile=jar文件所在路径
 

以pinyin4j-2.5.0为例:

 

1、将pinyin4j-2.5.0.jar件放在“D:\JAR_LIB”目录下(该目录任意)

2、执行命令:

mvn install:install-file -Dfile=D:\JAR_LIB\pinyin4j-2.5.0.jar -DgroupId=net.sourceforge.pinyin4j -DartifactId=pinyin4j -Dversion=2.5.0 -Dpackaging=jar  -DgeneratePom=true -DcreateChecksum=true

 

这样maven向本地仓库导入pinyin4j-2.5.0.jar 包就成功了。

 

3.pom.xml文件配置:  
<dependency>
<groupId>net.sourceforge.pinyin4j</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.0</version>
</dependency>

Spring4.03+Hibernate4.3.5整合_第3张图片
 
Spring4.03+Hibernate4.3.5整合_第4张图片
  最终导入本地仓库效果图

Spring4.03+Hibernate4.3.5整合_第5张图片
 

你可能感兴趣的:(Hibernate4)