温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

SSM框架怎么配置ApplicationContext.xml文件

发布时间:2022-09-30 09:52:00 来源:亿速云 阅读:119 作者:iii 栏目:开发技术

本文小编为大家详细介绍“SSM框架怎么配置ApplicationContext.xml文件”,内容详细,步骤清晰,细节处理妥当,希望这篇“SSM框架怎么配置ApplicationContext.xml文件”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

ApplicationContext.xml 文件

<beans xmlns="http://www.springframework.org/schema/beans" 
       xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:mvc ="http://www .springframework.org/schema/mvc" 
       xmlns:context ="http://www.springframework.org/schema/context" 
       xmlns:aop ="http://www.springframework.org/schema/aop" 
       xmlns:tx ="http://www.springframework.org/schema/tx" 
       xsi:schemaLocation ="http://www.springframework.org/schema/beans
        网址:www.springframework.org/schema/beans/spring-beans-4.3.xsd 
        http:www.springframework.org/schema/mvc 
        http:www.springframework.org/schema/mvc/spring-mvc-4.3.xsd 
        http:www.springframework.org/schema/context 
        http:www.springframework.org/schema/context/spring-context-4.3.xsd 
        http:www.springframework.org/schema/aop 
        http:www.springframework.org/schema/aop/spring-aop-4.3.xsd 
        http:www.springframework.org/schema/tx 
        http:www.springframework.org/schema/tx/spring-tx-4.3.xsd">
    <!--读取 db.properties-->
    <context:property-placeholder location="classpath:db.properties"/>
    <!--配置数据源-->
    <bean id="dataSource"类="org.apache.commons.dbcp2.BasicDataSource">
        <!--数据库驱动器-->
        <property name="driverClassName" value="${jdbc.driver}"/>
        <!--连接数据库的URL-->
        <property name="url" value="${jdbc.url}"/>
        <!--连接数据库的用户名-->
        <property name="username" value="${jdbc.username}"/>
        <!--连接数据库的密码-->
        <property name="password" value="${jdbc.password}"/>
        <!--最大连接数-->
        <property name="maxTotal" value="${jdbc.maxTotal}"/>
        <!--最大空闲数-->
        <property name="maxIdle" value="${jdbc.maxIdle}"/>
        <!--初始连接号-->
        <property name="initialSize" value="${jdbc.initialSize}"/>
    </豆>
    <!-- 事务管理器,依赖于数据源 -->
    <bean id="transactionManager"类="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </豆>
    <!--注意事项-->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:属性>
            <!--通信行为-->
            <tx:method name="save*" 传播="REQUIRED"/>
            <tx:method name="插入*" 传播="REQUIRED"/>
            <tx:method name="add*" 传播="REQUIRED"/>
            <tx:method name="create*" 传播="REQUIRED"/>
            <tx:method name="delete*" 传播="REQUIRED"/>
            <tx:method name="update*" 传播="REQUIRED"/>
            <tx:method name="find*" 传播="SUPPORTS" 只读="true"/>
            <tx:method name="select*" 传播="SUPPORTS" 只读="true"/>
            <tx:method name="get*" 传播="SUPPORTS" 只读="true"/>
        </tx:属性>
    </tx: 建议>
    <!--切面条-->
    <aop:配置>
        <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.ma.core.service.*.*(..))"/>
    </aop:config>
    <!--配置MyBatis工厂SqlSessionFactory-->
    <bean id="sqlSessionFactory" class ="org.mybatis.spring.SqlSessionFactoryBean">
        <!--注入数据源-->
        <property name="dataSource" ref="dataSource"/>
        <!--指定mapper文件的位置-->
        <property name="mapperLocations" value="classpath:mybatis/sqlmap/*.xml"/>
        <!--指定MyBatis的核心配置文件-->
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
    </豆>
    <!-- 接口开发,扫描com.itheima.core.dao包,可以扫描到这个包里写的接口 -->
    <bean类="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.ma.core.dao"/>
    </豆>
    <!-- 配置扫描@Service注解-->
    <context:component-scan base- package ="com.ma.core.service"/></beans>

读到这里,这篇“SSM框架怎么配置ApplicationContext.xml文件”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI