码迷,mamicode.com
首页 > 编程语言 > 详细

maven+spring+hibernate

时间:2014-09-03 19:38:27      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   os   io   java   ar   

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核心包引进

bubuko.com,布布扣
 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和数据库交互的需要

bubuko.com,布布扣
    <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 数据库账号信息

bubuko.com,布布扣
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

加载资源文件

bubuko.com,布布扣
   <!-- 加载资源文件 -->
  <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

数据源

bubuko.com,布布扣
  <!-- 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

 

maven+spring+hibernate

标签:des   style   blog   http   color   os   io   java   ar   

原文地址:http://www.cnblogs.com/svvs/p/3954350.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!