Spring的配置文件applicationContext.xml

博观而约取,厚积而薄发。这篇文章主要讲述Spring的配置文件applicationContext.xml相关的知识,希望能为你提供帮助。

1.applicationContext.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: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/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"> < !-- 扫描service部分的包 --> < !-- 配置连接池 --> < !-- 集成hibernate的jpa功能-工厂bean引入EntityManager--> < !-- Jpa 事务配置 --> < !-- 注解声明式事务管理 --> < !-- 注解声明式事务管理 --> < !-- Spring Data Jpa配置 --> < !-- 扫描service部分的包 --> < context:component-scan base-package="com.域名.模块名service" /> < context:property-placeholder location="classpath:jdbc.properties" /> < !-- 配置连接池 --> < bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> < !--连接数据4个属性 --> < property name="driverClassName" value="https://www.songbingjia.com/android/${jdbc.driverClassName}" /> < property name="url" value="https://www.songbingjia.com/android/${jdbc.url}" /> < property name="username" value="https://www.songbingjia.com/android/${jdbc.username}" /> < property name="password" value="https://www.songbingjia.com/android/${jdbc.password}" /> < !--maxActive: 最大连接数量 --> < property name="maxActive" value="https://www.songbingjia.com/android/150" /> < !--minIdle: 最小空闲连接 --> < property name="minIdle" value="https://www.songbingjia.com/android/5" /> < !--maxIdle: 最大空闲连接 --> < property name="maxIdle" value="https://www.songbingjia.com/android/20" /> < !--initialSize: 初始化连接 --> < property name="initialSize" value="https://www.songbingjia.com/android/30" /> < !-- 用来配置数据库断开后自动连接的 --> < !-- 连接被泄露时是否打印 --> < property name="logAbandoned" value="https://www.songbingjia.com/android/true" /> < !--removeAbandoned: 是否自动回收超时连接 --> < property name="removeAbandoned" value="https://www.songbingjia.com/android/true" /> < !--removeAbandonedTimeout: 超时时间(以秒数为单位) --> < property name="removeAbandonedTimeout" value="https://www.songbingjia.com/android/10" /> < !--maxWait: 超时等待时间以毫秒为单位 1000等于60秒 --> < property name="maxWait" value="https://www.songbingjia.com/android/1000" /> < !-- 在空闲连接回收器线程运行期间休眠的时间值,以毫秒为单位. --> < property name="timeBetweenEvictionRunsMillis" value="https://www.songbingjia.com/android/10000" /> < !-- 在每次空闲连接回收器线程(如果有)运行时检查的连接数量 --> < property name="numTestsPerEvictionRun" value="https://www.songbingjia.com/android/10" /> < !-- 1000 * 60 * 30 连接在池中保持空闲而不被空闲连接回收器线程 --> < property name="minEvictableIdleTimeMillis" value="https://www.songbingjia.com/android/10000" /> < property name="validationQuery" value="https://www.songbingjia.com/android/SELECT NOW() FROM DUAL" /> < /bean> < !-- 集成hibernate的jpa功能 --> < bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> < property name="dataSource" ref="dataSource" /> < !--待扫描的实体类包,不再需要persistence.xml了 --> < property name="packagesToScan" value="https://www.songbingjia.com/android/com.域名.模块名.domain" /> < !-- 3.配置JPA的实现 --> < !-- private JpaVendorAdapter jpaVendorAdapter; --> < property name="jpaVendorAdapter"> < bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> < !-- org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter --> < !-- private boolean showSql = false; 是否显示sql语句 --> < property name="showSql" value="https://www.songbingjia.com/android/true" /> < !-- private boolean generateDdl = false; 是否建表 --> < property name="generateDdl" value="https://www.songbingjia.com/android/false" /> < !-- private String databasePlatform; 原来方言 --> < property name="databasePlatform" value="https://www.songbingjia.com/android/org.hibernate.dialect.mysqlDialect" /> < /bean> < /property> < /bean> < !-- Jpa 事务配置 --> < bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> < property name="entityManagerFactory" ref="entityManagerFactory" /> < /bean> < !-- 注解声明式事务管理 --> < tx:annotation-driven /> < !-- Spring Data Jpa配置 ********************************************--> < !-- base-package:扫描的包 --> < jpa:repositories base-package="com.域名.模块名.repository" transaction-manager-ref="transactionManager" entity-manager-factory-ref="entityManagerFactory" factory-class="com.域名.模块名.repository.BaseRepositoryFactoryBean" /> < !-- factory-class="com.域名.模块名.repository.BaseRepositoryFactoryBean"这个是自定义增强后的 BaseRepositoryFactoryBean--> < /beans>

 
 
2.  applicationContext-mvc.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:mvc="http://www.springframework.org/schema/mvc" 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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd "> < !--!!!!5件套!!!!!--> < !-- 1.对静态资源进行放行 --> < !-- 2.扫描controller部分的包 --> < !-- 3.添加mvc对@RequestMapping等注解的支持 --> < !-- 4.ViewResolver 视图解析器 (struts2视图类型类似) --> < !-- 5.配置文件上传解析器。 --> < !-- 1.对静态资源进行放行 --> < mvc:default-servlet-handler /> < !-- 2.扫描controller部分的包 --> < !-- @Component组件, @Repository持久层, @Service业务逻辑层, and @Controller控制器 --> < context:component-scan base-package="com.域名.模块名.web.controller" /> < !-- 3.添加mvc对@RequestMapping等注解的支持 --> < mvc:annotation-driven /> < !-- 4.ViewResolver 视图解析器 (struts2视图类型类似) --> < bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> < !-- 设置视图路径的前后缀,该配置可以让我们写视图路径的时候更简单。 --> < !-- 希望跳转jsp是[/WEB-INF/views/前缀][xxx变量][.jsp后缀] --> < !-- * @see #setPrefix --> < property name="prefix" value="https://www.songbingjia.com/WEB-INF/views/" /> < !-- * @see #setSuffix --> < property name="suffix" value="https://www.songbingjia.com/android/.jsp" /> < /bean> < !-- 5.配置文件上传解析器。 --> < bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> < !-- 设置上传文件的最大尺寸为1MB --> < property name="maxUploadSize"> < value> 1048576< /value> < /property> < /bean> < /beans>

【Spring的配置文件applicationContext.xml】 


    推荐阅读