spring配置文件的基本写法
2017-09-18 09:02
411 查看
<?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:p="http://www.springframework.org/schema/p" 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-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> <!-- 扫描注释的类 --> <context:component-scan base-package="com.starry.dao,com.starry.service,com.starry.web"></context:component-scan> <!-- 连接数据库 --> <bean id="datasourse" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" scope="singleton"> <!-- 连接数据库配置 --> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property><!-- 数据库连接driver --> <property name="url" value="jdbc:mysql://localhost:3306/springmybatis?allowMultiQueries=true&characterEncoding=UTF-8&useSSL=false"></property> <property name="username" value="root"></property><!-- 数据库连接username --> <property name="password" value="123456"></property><!-- 数据库连接password --> <!-- 性能配置 --> <property name="initialSize" value="10"></property> <!-- 初始化放多少个连接 --> <property name="maxActive" value="20"></property> <!-- 处于活动的最大连接数量 --> <property name="maxIdle" value="10"></property> <!-- 不活动的连接最多放多少个 --> <property name="minIdle" value="2"></property> <!-- 不活动的连接最少放多少个 --> <property name="maxWait" value="2000"></property> <!-- 最长等待时间 2000毫秒 --> </bean> <!-- sqlsessionFactory --> <bean id="fac" class="org.mybatis.spring.SqlSessionFactoryBean" > <property name="dataSource" ref="datasourse"></property> <property name="configLocation" value="classpath:mybatis.xml"></property> </bean> <!-- MapperScannerConfigurer 实体类--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.starry.dao"></property> <property name="sqlSessionFactoryBeanName" value="fac"></property> </bean> <!-- 视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="suffix" value=".jsp"></property> <property name="prefix" value="/view/"></property> </bean> <!-- 拦截器 --> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/login/*"/> <bean class="com.starry.interceptor.UserInteceptor"></bean> </mvc:interceptor> </mvc:interceptors> <!-- jackson传递数据 --> <bean id="jsonconverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=utf-8</value> </list> </property> </bean> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="jsonconverter"/> </list> </property> </bean> <!-- jackson传递数据 --> <!--验证器 --> <bean id="myvalbean" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"> <property name="providerClass" value="org.hibernate.validator.HibernateValidator"/> <property name="validationMessageSource" ref="messageresource"></property> </bean> <!-- bean加属性转换 ,验证注解 --> <!-- 开启除了springmvc基础注解之外的注解信息管理 --> <mvc:annotation-driven validator="myvalbean" conversion-service="conversionService"> <mvc:message-converters> <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=utf-8</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven> <!-- 全局转换器 --> <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"> <property name="converters"> <list> <!-- <bean class="com.starry.entity.MyConverter2" /> --> <bean class="com.starry.entity.MyConverter" /> </list> </property> </bean> <!-- 资源文件的加载类 --> <bean id="messageresource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basenames"> <list> <value>classpath:messages</value> </list> </property> <property name="fileEncodings" value="utf-8"/> <property name="cacheSeconds" value="120"/> </bean> <!-- 文件上传 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> </bean> </beans>
相关文章推荐
- 玩转Spring MVC(三)----spring基本配置文件
- springboot 配置文件 .properties和.yml的写法区别
- spring使用注解时配置文件的写法
- spring+hibernate+struts文件基本配置
- jAVA SpringBoot(1)---pom.xml文件基本配置
- 【spring】配置文件命名空间写法
- 使用Gradle构建SpringBoot工程系列:第四篇:项目初始化(编辑build.gradle文件,引入项目基本配置及依赖)
- spring使用注解时配置文件的写法
- spring 配置文件中的ref元素的作用是什么?它的两个基本属性是什么?
- Hibernate注解配置 在Spring的配置文件里写法
- SpringCloud系列九:SpringCloudConfig 基础配置(SpringCloudConfig 的基本概念、配置 SpringCloudConfig 服务端、抓取配置文件信息、客户端使用 SpringCloudConfig 进行配置、单仓库目录匹配、应用仓库自动选择、仓库匹配模式)
- Spring配置文件基本作用
- Spring-Mybatis配置文件基本配置
- 学习Spring(二) -- Spring配置文件基本属性详解
- Hibernate注解配置 在Spring的配置文件里写法
- spring配置文件的一般写法(集成hibernate) (applicationContext.xml)
- Spring配置文件写法
- 一个spring 基本知识的微博(怎么加载多个xml、多个property文件、aop配置、监视器)
- SSM框架整合之Spring主配置文件的写法
- SpringBoot基本讲解(配置文件)