无敌全的application.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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

    <!--使Spring支持自动检测组件,如注解的@Controller -->
    <context:component-scan base-package="com.parry.test.*" />
    <bean
        class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" />
    <bean
        class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />

    <!-- 数据库配置 -->
    <bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource"
        destroy-method="close">
        <property name="driverClass" value="com.mysql.jdbc.Driver" />
         <!-- 测试数据库 -->
        <property name="jdbcUrl"
            value="jdbc:mysql://127.0.0.1:3066/TESTDB?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true" />
        <property name="username" value="root" />
        <property name="password" value="root" />
        
        <!-- 检查数据库连接池中空闲连接的间隔时间,单位是分,默认值:240,如果要取消则设置为0 -->
        <property name="idleConnectionTestPeriod" value="240" />
        <!-- 连接池中未使用的链接最大存活时间,单位是分,默认值:30,如果要永远存活设置为0 -->
        <!-- 数据库连接池过期时间应小于等于mysql的过期时间和mycat的过期时间 -->
        <property name="idleMaxAge" value="20" />
        <!-- 每个分区最大的连接数 -->
        <property name="maxConnectionsPerPartition" value="100" />
        <!-- 每个分区最小的连接数 -->
        <property name="minConnectionsPerPartition" value="20" />
        <!-- 分区数 ,默认值2,最小1,推荐3-4,视应用而定 -->
        <property name="partitionCount" value="1" />
        <!-- 每次去拿数据库连接的时候一次性要拿几个,默认值:2 -->
        <property name="acquireIncrement" value="2" />
        <!-- 缓存prepared statements的大小,默认值:0 -->
        <property name="statementsCacheSize" value="0" />
        <property name="connectionTimeoutInMs" value="100" />
        <!-- 每个分区释放链接助理进程的数量,默认值:3,除非你的一个数据库连接的时间内做了很多工作,不然过多的助理进程会影响你的性能 -->
        <property name="releaseHelperThreads" value="3" />
    </bean>
    <!-- 配置SqlSessionFactoryBean -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation" value="classpath:mybatis.xml" />
        <!-- mapper和resultmap配置路径 -->
        <property name="mapperLocations">
            <list>
                <!-- 表示在com.sfpay.mapper包或以下所有目录中,以-resultmap.xml结尾所有文件 -->
                <value>classpath:com/parry/test/dao/config/*.xml</value>
            </list>
        </property>
    </bean>
    <!-- 配置mapper接口 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.cn21.calendar.dao" />
    </bean>
    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSessionFactory" />
    </bean>
    <!-- 事务配置 -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <!-- 用于持有ApplicationContext,可以使用SpringContextHolder.getBean('xxxx')的静态方法得到spring 
        bean对象 -->
    <bean class="com.parry.test.springcontext.SpringContextHolder"
        lazy-init="false" />

    <!-- 定时器 begin -->
    <!-- 赛程 调度业务对象 -->
    <bean id="deletePastOrderJob" class="com.parry.test.function.PublicTypeFunction" />
    <!-- 赛程 调度业务 -->
    <bean id="deletePastOrderTask"
        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="deletePastOrderJob" />
        <property name="targetMethod" value="deletePastOrder" />
    </bean>
    <!-- 赛程 调度器触发器 每天早上07:00执行一次 -->
    <bean id="deletePastOrderTaskTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="deletePastOrderTask" />
        <property name="cronExpression" value="0 13 09 * * ? *" />
    </bean>
    <!-- 设置调度 -->
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <!-- <ref bean="deletePastOrderTaskTrigger" /> -->
            </list>
        </property>
    </bean>
    <!-- 定时器 end -->
    <!-- 服务器启动,初始化项目配置参数 -->
    <bean name="InitalizeBean" class="com.parry.test.configure.impl.InitalizeBean" />
</beans>

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Spring.xml是Spring框架中的配置文件,用于配置和管理应用程序中的各种组件和依赖关系。它是基于XML格式的,并且是Spring框架的核心配置文件之一。 在Spring.xml中,可以定义以下内容: 1. Bean定义:通过定义Bean,可以告诉Spring框架如何创建和管理对象。每个Bean都有一个唯一的ID和一个类的限定名。可以通过配置构造函数参数、属性注入、依赖关系等来配置Bean。 2. 依赖注入:通过配置依赖注入,可以让Spring框架自动管理对象之间的依赖关系。可以使用构造函数注入、Setter方法注入或字段注入来实现依赖注入。 3. 切面配置:通过配置切面,可以实现面向切面编程(AOP)的功能。可以定义切点、通知和切面,并将它们应用到指定的目标对象上。 4. 属性配置:可以在Spring.xml配置一些属性,如数据库连接信息、日志级别等。这些属性可以在应用程序中通过Spring框架进行读取和使用。 5. 声明式事务管理:可以通过配置声明式事务管理,来实现对数据库事务的管理。可以指定事务传播行为、隔离级别等属性。 6. 其他配置:还可以在Spring.xml配置其他一些内容,如国际化资源、拦截器、视图解析器等。 总的来说,Spring.xml配置文件是一个非常重要的文件,用于定义和配置应用程序中的各种组件和功能。通过合理配置Spring.xml,可以实现对应用程序的灵活管理和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值