applicationContext.xml配置文件中常用配置

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:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.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/tx http://www.springframework.org/schema/tx/spring-tx.xsd"
        >
<!--    配置注解包-->
    <context:component-scan base-package="sbb.controller,sbb.service"/>

<!--    配置数据源-->
    <bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="url" value="jdbc:mysql://localhost:3306/batis?serverTimezone=Asia/Shanghai"></property>
        <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
        <property name="username" value="root"></property>
        <property name="password" value="111111"></property>
    </bean>
<!--    配置factory-->
    <bean name="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="configLocation" value="classpath:Mybatis-config.xml"></property>
        <property name="mapperLocations" value="classpath:mapping/*.xml"></property>
    </bean>
<!--    配置自动注入mapper-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" >
        <property name="basePackage" value="sbb.mapper"></property>
        <property name="sqlSessionFactoryBeanName" value="sessionFactory"></property>
    </bean>
<!--    配置事务-->
    <bean name="tm" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    
    <tx:annotation-driven transaction-manager="tm"></tx:annotation-driven>

<!--    拼接路径前缀后缀-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"></property>
        <property name="suffix" value=".jsp"></property>
     </bean>

<!--    配置转换器-->
    <bean name="convert" class="org.springframework.context.support.ConversionServiceFactoryBean">
        <property name="converters">
            <set>
                <bean class="sbb.conver.DateConver">
                    <property name="fmtdates">
                        <array>
                            <value>YYYY-MM-dd</value>
                            <value>YYYY/MM/dd</value>
                            <value>YYYY.MM.dd</value>
                        </array>
                    </property>
                </bean>
            </set>
        </property>
    </bean>

<!--    配置拦截器-->
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/sys/**"/>
            <bean class="sbb.interceptor.MyInterceptor"></bean>
        </mvc:interceptor>
    </mvc:interceptors>


<!--    设置JSON返回配置-->
    <mvc:annotation-driven conversion-service="convert">
        <mvc:message-converters>
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="defaultCharset" value="UTF-8"></property>
<!--                <property name="supportedMediaTypes">-->
<!--                    <list>-->
<!--                        <value>text/html; charset=UTF-8</value>-->
<!--                    </list>-->
<!--                </property>-->
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>
<!--    放过静态文件路径-->
    <mvc:resources mapping="/statics/**" location="/statics/"></mvc:resources>
<!--    <mvc:resources mapping="/statics/css/**" location="/statics/css/"></mvc:resources>-->
<!--    <mvc:resources mapping="/statics/js/**" location="/statics/js/"></mvc:resources>-->
<!--    <mvc:resources mapping="/statics/images/**" location="/statics/images/"></mvc:resources>-->

<!--    传输文件-->
    <bean name="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="5000000"></property>
        <property name="defaultEncoding" value="UTF-8"></property>
    </bean>
    </beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. web.xml:这是一个Java Web 项目的核心配置文件,主要用于配置Servlet、Filter、Listener等Web组件,并且定义了Servlet容器的一些基本配置,如编码、Session管理、错误页面等。其常用配置包括: - 配置Servlet:用于处理HTTP请求的Java类。 - 配置Filter:用于对HTTP请求进行过滤和处理。 - 配置Listener:用于监听Web应用程序的生命周期事件。 2. springmvc-config.xml:这是一个Spring MVC框架的配置文件,主要用于配置Spring MVC的核心组件,如HandlerMapping、ViewResolver、Interceptor等。其常用配置包括: - 配置HandlerMapping:用于映射请求到相应的控制器方法。 - 配置ViewResolver:用于将控制器方法返回的逻辑视图名映射到实际的视图模板。 - 配置Interceptor:用于拦截请求,在处理请求前或处理请求后进行一些操作,如权限控制、日志记录等。 3. spring-mybatis.xml:这是一个整合Spring和MyBatis框架的配置文件,主要用于配置数据库连接、事务管理、Mapper接口扫描等。其常用配置包括: - 配置数据源:用于连接数据库,设置连接池等。 - 配置事务管理器:用于管理数据库事务,保证事务的一致性和可靠性。 - 配置Mapper接口扫描:用于自动扫描Mapper接口,并将其注册为Spring的Bean。 4. applicationcontext.xml:这是一个Spring框架的核心配置文件,主要用于配置Spring容器的各种Bean,包括Service、DAO、Interceptor等。其常用配置包括: - 配置Bean:用于定义Spring容器的各种Bean。 - 配置AOP:用于实现面向切面编程,如事务管理、日志记录等。 - 配置属性文件:用于加载外部的属性文件,如数据库连接信息、邮件服务器信息等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值