Deep learning 2021-09-27 15:23 采纳率: 69.2%
浏览 157
已结题

org.springframework.core.KotlinDetector.isSuspendingFunction(Ljava/lang/reflect/Method;)Z

img


在学习spring事务的时候,我在Servcie类上或者类方法上加上@Transactional后,运行测试代码就会报错。不添加注解@Transactional时,就没有报错,在网上也没有收到关于这个报错的问题。所以想请教一下有没有人碰到过这种问题?

java.lang.NoSuchMethodError: org.springframework.core.KotlinDetector.isSuspendingFunction(Ljava/lang/reflect/Method;)Z

Service

@Service
@Transactional
public class UserService {

    @Autowired
    private UserDao userDao;

    //转账的方法
    public void accountMoney(){
            //lucy少一百
            userDao.reduceMoney();

            //模拟异常
            //int i = 10/0;

            //Marry多一百
            userDao.addMoney();
    }


}

DaoImpl

@Repository
public class UserDaoImpl implements UserDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    //lucy转账100给marry
    @Override
    public void addMoney() {
        String sql = "update t_account set account=account-? where username=?";
        jdbcTemplate.update(sql,100,"lucy");
    }

    @Override
    public void reduceMoney() {
        String sql = "update t_account set account=account+? where username=?";
        jdbcTemplate.update(sql,100,"Marry");
    }
}

配置文件.

<?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:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://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/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!-- 开启组件扫描 -->
    <context:component-scan base-package="com.jbit"></context:component-scan>

    <!-- 数据库连接池 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
          destroy-method="close">
        <!-- characterEncoding=UTF-8serverTimezone=UTC -->
        <property name="url" value="jdbc:mysql://localhost:3306/jdbctemp?serverTimezone=UTC" />
        <property name="username" value="root" />
        <property name="password" value="root" />
        <property name="driverClassName" value="com.mysql.cj.jdbc.Driver" />
    </bean>

    <!-- jdbcTemplate对象 -->
    <bean class="org.springframework.jdbc.core.JdbcTemplate" id="jdbcTemplate">
        <!-- 注入DataSource -->
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <!-- 创建事务管理器 -->
    <bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager">
        <!-- 注入数据源 -->
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <!-- 开启事务注解 -->
    <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>
</beans>

@Test
    public void testAccount(){
        //PlatformTransactionManager
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        UserService userService = context.getBean("userService", UserService.class);
        userService.accountMoney();
    }
  • 写回答

5条回答 默认 最新

  • Tomshidi 2021-09-27 15:33
    关注

    spring-tx包和spring-core包版本不一致?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 10月6日
  • 已采纳回答 9月28日
  • 创建了问题 9月27日

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题