You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.3 KiB

<?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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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
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">
<!-- 启用自动扫描 -->
<context:component-scan base-package="com"></context:component-scan>
<!-- 启用springmvc相关Annotation的处理器 -->
<mvc:annotation-driven />
<!-- 采用注释的方式配置bean -->
<context:annotation-config />
<!--proxy-target-class="true"强制使用cglib代理 如果为false则spring会自动选择-->
<aop:aspectj-autoproxy proxy-target-class="true" />
<!-- 配置dbcp数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="org.gjt.mm.mysql.Driver" />
<!--<property name="driverClassName" value="com.mysql.cj.jdbc.Driver" />-->
<!-- 数据库连接字符串 -->
<property name="url" value="jdbc:mysql://localhost:3306/mysql?characterEncoding=utf8" />
<!-- 数据库用户名 -->
<property name="username" value="root" />
<!-- 数据库密码 -->
<property name="password" value="666666" />
<!-- 最大连接数 -->
<property name="maxTotal" value="80" />
<!-- 最大空闲连接数 -->
<property name="maxIdle" value="10" />
<!-- 初始化连接数 -->
<property name="initialSize" value="5" />
</bean>
<!-- 配置mybitasSqlSessionFactoryBean -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis.xml"></property>
<!-- 扫描entity包 使用别名 -->
<property name="typeAliasesPackage" value="com.entity" />
<property name="plugins">
<set>
<!--配置pageHelper 分页插件 -->
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<props>
<!--方言: -->
<prop key="helperDialect">mysql</prop>
</props>
</property>
</bean>
</set>
</property>
</bean>
<!-- 配置扫描DAO接口包动态实现DAO接口注入到spring容器中 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 注入sqlSessionFactory -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
<!-- 给出需要扫描DAO接口包 -->
<property name="basePackage" value="com.dao" />
</bean>
<!-- 配置SqlSessionTemplate -->
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>
<!-- 事务配置 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 使用annotation注解方式配置事务 -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- 定义跳转的文件的前后缀 ,视图模式配置-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 这里的配置是自动给后面action的方法return的字符串加上前缀和后缀变成一个 可用的url地址 -->
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 支持上传文件 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="104857600" />
<property name="maxInMemorySize" value="4096" />
<property name="defaultEncoding" value="UTF-8"></property>
</bean>
</beans>