【spring配置】 一组配置文件引出的问题

applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context-3.0.xsd
               http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
            ">

    <context:property-placeholder location="classpath*:javaniu.properties" />
    <context:annotation-config />
    <context:component-scan base-package="com.javaniu" />
    <mvc:annotation-driven />
    <import resource="hibernate-context.xml" />
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix">
            <value>/WEB-INF/jsp/</value>
        </property>
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

hibernate-context.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:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx.xsd
            http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
            ">

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${datasource.connection.driver_class}" />
        <property name="jdbcUrl" value="${datasource.connection.url}" />
        <property name="user" value="${datasource.connection.username}" />
        <property name="password" value="${datasource.connection.password}" />
        <property name="minPoolSize" value="${datasource.connection.minPoolSize}" />
        <!--连接池中保留的最大连接数。Default: 15 -->
        <property name="maxPoolSize" value="${datasource.connection.maxPoolSize}" />
        <!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
        <property name="maxIdleTime" value="${datasource.connection.maxIdleTime}" />
        <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
        <property name="acquireIncrement" value="${datasource.connection.acquireIncrement}" />
        <!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements 属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。
            如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 -->
        <property name="maxStatements" value="${datasource.connection.maxStatements}" />
        <!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 -->
        <property name="maxStatementsPerConnection"
            value="${datasource.connection.maxStatementsPerConnection}" />
        <!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
        <property name="initialPoolSize" value="${datasource.connection.initialPoolSize}" />
        <!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
        <property name="idleConnectionTestPeriod"
            value="${datasource.connection.idleConnectionTestPeriod}" />
        <!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
        <property name="acquireRetryAttempts"
            value="${datasource.connection.acquireRetryAttempts}" />
        <!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效 保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试
            获取连接失败后该数据源将申明已断开并永久关闭。Default: false -->
        <property name="breakAfterAcquireFailure"
            value="${datasource.connection.breakAfterAcquireFailure}" />
        <!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的 时候都将校验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable
            等方法来提升连接测试的性能。Default: false -->
        <property name="testConnectionOnCheckout"
            value="${datasource.connection.testConnectionOnCheckout}" />
        <property name="checkoutTimeout" value="${datasource.connection.checkoutTimeout}" />
        <property name="testConnectionOnCheckin"
            value="${datasource.connection.testConnectionOnCheckin}" />
        <property name="automaticTestTable" value="${datasource.connection.automaticTestTable}" />
        <property name="acquireRetryDelay" value="${datasource.connection.acquireRetryDelay}" />
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
    <!-- Declare a JPA entityManagerFactory -->
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

        <property name="packagesToScan" value="com.javaniu" />
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="${hibernate.showSql}" />
                <property name="generateDdl" value="true" />
            </bean>
        </property>
    </bean>
    <!-- Declare a transaction manager -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <!-- Where to find repositories -->
    <jpa:repositories base-package="com.javaniu.repository" />

</beans>   

javaniu.properties

# database properties
## datasource
datasource.connection.driver_class=com.mysql.jdbc.Driver
datasource.connection.url=jdbc:mysql://10.32.11.74:3306/jparest?useUnicode=true&characterEncoding=utf-8
datasource.connection.username=root
datasource.connection.password=123456
datasource.connection.minPoolSize=1
datasource.connection.maxPoolSize=20
datasource.connection.maxIdleTime=30
datasource.connection.acquireIncrement=10
datasource.connection.maxStatements=0
datasource.connection.maxStatementsPerConnection=0
datasource.connection.initialPoolSize=5
datasource.connection.idleConnectionTestPeriod=30
datasource.connection.acquireRetryAttempts=30
datasource.connection.breakAfterAcquireFailure=true
datasource.connection.testConnectionOnCheckout=true
datasource.connection.checkoutTimeout=3000
datasource.connection.testConnectionOnCheckin=true
datasource.connection.automaticTestTable = c3p0TestTable
datasource.connection.acquireRetryDelay = 1000

hibernate.showSql=true
时间: 2024-08-11 03:20:25

【spring配置】 一组配置文件引出的问题的相关文章

关于spring mvc的配置文件

1. Web.xml <!--配置页面控制器--> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</par

spring(一)--spring/springmvc/spring+hibernate(mybatis)配置文件

这篇文章用来总结一下spring,springmvc,spring+mybatis,spring+hibernate的配置文件 1.web.xml 要使用spring,必须在web.xml中定义分发器等信息,基本的配置信息如下: <?xml version="1.0" encoding= "UTF-8"?> <web-app version= "3.0" xmlns="http://java.sun.com/xml/n

spring配置hibernate的sessionFactory的几种方法

分类: JAVA Spring Hibernate 2013-01-27 20:47  1851人阅读  评论(0)  收藏  举报 spring配置hibernate的sessionFactory 之前用spring2+hibernate3+struts2开发了一个彩信发布系统,由于第一次使用此架构,造成applicationContext.xml中的配置非常冗长,而且经常因为更改一个小配置项(例:数据库ip.用户名.密码等)将此文件作修改,这及不利于项目维护,万一粗心造成其他地方变动,会对本

Spring/Maven/MyBatis配置文件结合properties文件使用

使用properties文件也叫注入,比如把一些常用的配置项写入到这个文件,然后在Spring的XML配置文件中使用EL表达式去获取. 这种方式不只Spring可以使用,同样MyBatis也可以使用,只不过加载的方式不一样,但是获取值同样是EL表达式.具体的参考官方文档. properties语法参考:https://zh.wikipedia.org/wiki/.properties,注意转移字符. Spring: 本次使用的例子来自这章http://www.cnblogs.com/EasonJ

spring配置中,properties文件以及xml文件配置问题

spring方便我们的项目快速搭建,功能强大,自然也会是体系复杂! 这里说下配置文件properties管理的问题. 一些不涉及到代码逻辑,仅仅只是配置数据,可以放在xxxx.properties文件里面,项目功能复杂的时候,往往properties文件很多,这时,就比较容易让人困惑,有些properties的文件内容总是加载不起来,应用启动时,就不断爆出错误,说某某参数加载失败,这个是什么原因呢? 其实,这个是spring配置的时候,org.springframework.beans.fact

quartz与spring的结合 配置文件

例子是利用spring的org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean 类,能够创建任务,创建任务的时间间隔,开启. 分四步: 1.定义自己的bean <bean id="AuditTimeoutTimer" class="*****.TimeoutWarningTimer"></bean> 2.定义任务,任务中有两个属性,调用的类和方法 <

spring Quartz基于配置文件和注解的实现

这里仅仅是做简单的记录怎样实现. 一.基于配置文件的实现 ①编写须要调度的类 package com.study; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; //@Component public class QuartzJob { public QuartzJob(){ System.out.println("Quart

Spring的DataSource配置、将Hibernate配置全部写到Spring配置

DataSource可以集中管理数据库连接,减少维护工作量,使部署更简单: Spring的DataSource配置:(Spring数据源配置)这里使用dbcp,还有很多其他的如c3p0,jdbc,jndi等 DataSource和定义普通Bean一样,指定id.类别,注入属性: 站点停止时,应该调用DataSource的close方法,通过destroy-method属性配置实现: 1,在Spring配置文件配置DataSource的bean: <bean id="dataSource&q

SSH框架系列:Spring配置多个数据源

问题:有开源框架mysql的 ,还有旧系统 sqlserver2000的,解决这些问题总有些成长. 解决sqlserver安装环境:http://qdh68.blog.163.com/blog/static/13756126201261742437357/ 别说sqlserver2000不怎么样,最起码那友好的管理叫你明白数据库. 2.  先说配置jdbc:如果sqlserver 2000以上还好 找到jar包 ,按目录加载到maven仓库,安装一下 http://outofmemory.cn/