spring 临时数据访问资源异常

rn0zuynd  于 2022-11-28  发布在  Spring
关注(0)|答案(1)|浏览(101)

我在第一次调用服务时遇到了一个问题,第二次成功检索数据时抛出了错误org.springframework.dao.TransientDataAccessResourceException: SqlSessionFactory must be using a SpringManagedTransactionFactory in order to use Spring transaction synchronization
UserServiceEJB.java

@Stateless(name = "UserService")
@Interceptors
@Transactional
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Local(UserService.class)
public class UserServiceEJB implements UserService {

        public UsersDetailsPojo[] getUsersList(UserRequest userRequest) {
               return getUsers(userRequest);
        }
}

config.xml

<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:jee="http://www.springframework.org/schema/jee"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:c="http://www.springframework.org/schema/c"
    xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
        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">
  <!-- MyBatis SqlSessionFactory -->
<bean id="mybatisTransactionManager" class="org.apache.ibatis.transaction.managed.ManagedTransactionFactory" />
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate" c:_0-ref="sqlSessionFactory" />
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
        p:dataSource-ref="dataSource" p:configLocation="classpath:mybatis-config.xml"
        p:transactionFactory-ref="mybatisTransactionManager" />

获取以下错误

org.springframework.dao.TransientDataAccessResourceException: SqlSessionFactory must be using a SpringManagedTransactionFactory in order to use Spring transaction synchronization
        at org.mybatis.spring.SqlSessionUtils.registerSessionHolder(SqlSessionUtils.java:142)
        at org.mybatis.spring.SqlSessionUtils.getSqlSession(SqlSessionUtils.java:102)
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:428)
        at com.sun.proxy.$Proxy123.selectList(Unknown Source)
        at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)

有什么建议吗?请帮忙。

voase2hg

voase2hg1#

删除此行并重试-

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
    p:dataSource-ref="dataSource" p:configLocation="classpath:mybatis-config.xml"
    p:transactionFactory-ref="mybatisTransactionManager" />

相关问题