Carl_Go 2021-07-26 00:16 采纳率: 100%
浏览 26
已结题

Javamvc三层框架

就是这样不知道错误在哪啊
img

img

  • 写回答

3条回答 默认 最新

  • CSDN专家-微编程 2021-07-26 06:54
    关注

    你这个就是mybatis链接数据库,使用连接池报的异常,就在你mybatis链接数据库的xml里面,你应该使用spring进行集成了吧,在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:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
            https://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/aop
            https://www.springframework.org/schema/aop/spring-aop.xsd">
    <!--    &lt;!&ndash;引入小配置文件 读取jdbc.properties&ndash;&gt;-->
        <context:property-placeholder location="classpath:common.properties" system-properties-mode="NEVER"/>
        <bean class="com.alibaba.druid.pool.DruidDataSource" id="dataSource">
            <property name="driverClassName" value="${driverClassName}"/>
            <property name="url" value="${url}"/>
            <property name="username" value="${username}"/>
            <property name="password" value="${password}"/>
        </bean>
        <!-- 定义SqlSessionFactory,管理mybatis的数据库连接sqksession对象-->
        <bean class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean" id="sqlSessionFactory">
            <property name="dataSource" ref="dataSource"/>
            <!--配置实体类的包名,自动为实体配置短类名的别名-->
            <property name="typeAliasesPackage" value="entity"/>
            <property name="mapperLocations">
                <!-- 配置mapper.xml的路径-->
                <list>
                    <value>classpath:dao/*Dao.xml</value>
                </list>
            </property>
            <property name="plugins">
                <array>
                    <bean class="com.github.pagehelper.PageInterceptor"/>
                </array>
            </property>
        </bean>
        <!--让spring扫描dao包,创建出dao接口的实现类,并把实现类配置为bean标签
    自动创建Mapper实现类对象
    自动扫描basePackage包下的Mapper接口,自动创建Mapper接口的实现类对象-->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <!-- mapper实现类对象的id规则:接口名首字母小写
            UserMapper ==> userMapper
            BookMapper ==> bookMapper -->
            <property name="basePackage" value="dao"/>
        </bean>
        <!-- 配置要扫描注解的包-->
        <context:component-scan base-package="service"/>
        <!--事务管理器-->
        <bean id="tm" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource"/>
        </bean>
        <!--把事务管理器注入到事务通知类-->
        <tx:advice id="txAdvice" transaction-manager="tm">
    <!--事务的策略,类中不同方法使用不同的事务策略-->
            <tx:attributes>
                <!--以select的方法,都是只读的方法,不用使用事务-->
                <tx:method name="select*" read-only="true"/>
                <!--除了select开头的方法,其余的方法都必须使用事务-->
                <tx:method name="*" propagation="REQUIRED"/>
            </tx:attributes>
        </tx:advice>
        <!--配置切入点和织入-->
        <aop:config>
            <aop:pointcut id="pc" expression="execution(* service..*.*(..))"/>
            <aop:advisor advice-ref="txAdvice" pointcut-ref="pc"/>
        </aop:config>
    </beans>
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 10月4日
  • 已采纳回答 9月26日
  • 创建了问题 7月26日

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!