zoukankan      html  css  js  c++  java
  • maven+spring+hibernate

    1.配置文件

    pom.xml  

    指定一个spring.version变量

      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring.version>4.0.0.RELEASE</spring.version>
      </properties>
    

    把spring+hibernate核心包引进

     1     <dependency>
     2         <groupId>org.springframework</groupId>
     3         <artifactId>spring-web</artifactId>
     4         <version>${spring.version}</version>
     5     </dependency>
     6     <dependency>
     7         <groupId>org.springframework</groupId>
     8         <artifactId>spring-orm</artifactId>
     9         <version>${spring.version}</version>
    10     </dependency>
    11     <dependency>
    12         <groupId>org.hibernate</groupId>
    13         <artifactId>hibernate-core</artifactId>
    14         <version>3.6.10.Final</version>
    15     </dependency>
    View Code

    还需要 web和数据库交互的需要

        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-webmvc</artifactId>
          <version>4.0.0.RELEASE</version>
        </dependency>
        <dependency>
          <groupId>org.codehaus.jackson</groupId>
          <artifactId>jackson-mapper-asl</artifactId>
          <version>1.9.13</version>
        </dependency>
        <dependency>
          <groupId>javassist</groupId>
          <artifactId>javassist</artifactId>
          <version>3.11.0.GA</version>
        </dependency>
        <dependency>
          <groupId>c3p0</groupId>
          <artifactId>c3p0</artifactId>
          <version>0.9.1.2</version>
        </dependency>
        <dependency>
          <groupId>com.mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>5.0.8</version>
          <classifier>bin</classifier>
        </dependency>
    View Code

    jdbc.properties 数据库账号信息

    jdbc.driverClassName=com.mysql.jdbc.Driver
    jdbc.url=jdbc:mysql://192.168.1.2:3306/test?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF8
    jdbc.user=root
    jdbc.password=root
    View Code

    application-hiberntate.xml

    加载资源文件

       <!-- 加载资源文件 -->
      <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
          <property name="locations">
              <list>
                   <value>classpath:jdbc.properties</value>
              </list>
          </property>
           <property name="fileEncoding">
               <value>UTF-8</value>
           </property>
          <property name="ignoreUnresolvablePlaceholders" value="true" />
      </bean>
    View Code

    数据源

      <!-- c3po 数据源 -->
      <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass"><value>${jdbc.driverClassName}</value></property>
        <property name="jdbcUrl"><value>${jdbc.url}</value></property>
        <property name="user"><value>${jdbc.user}</value></property>
        <property name="password"><value>${jdbc.password}</value></property>
        <property name="minPoolSize"><value>10</value></property>
        <property name="maxPoolSize"><value>300</value></property>
        <property name="maxIdleTime"><value>120</value></property>
        <property name="idleConnectionTestPeriod"><value>3</value></property>
        <property name="initialPoolSize"><value>10</value></property>
        <property name="numHelperThreads"><value>3</value></property>
        <property name="acquireRetryAttempts"><value>8</value></property>
        <property name="testConnectionOnCheckin" value="false"/>
      </bean>
    View Code
  • 相关阅读:
    jQuery自定义插件
    jQuery基础入门学习
    jQuery事件机制
    css实现块级元素的水平居中的2种常用方法
    文本编辑的css常用属性
    js的事件的绑定
    js正则表达式(常用)
    汇编初入门debug实操
    JAVA新手笔记 Intent对象和Bundle对象
    OS X运行AFNI的AlphaSim提示libgomp.1.dylib找不到的解决办法
  • 原文地址:https://www.cnblogs.com/svvs/p/3954350.html
Copyright © 2011-2022 走看看