EnableTransactionManagement 无法解析为类型

Sha*_*aun 2 java pom.xml maven

package com.shaun.spring.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan("com.shaun.spring")
@EnableTransactionManagement
public class ApplicationContextConfig {

    // @Bean configurations go here...

}
Run Code Online (Sandbox Code Playgroud)

我对@EnableTransactionManagement 有问题,发生的以下错误是:EnableTransactionManagement 无法解析为类型。

我的 pom.xml 中有以下依赖项:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>4.1.6.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用以下导入:

import org.springframework.transaction.annotation.EnableTransactionManagement;
Run Code Online (Sandbox Code Playgroud)

这给了我以下错误:

The import org.springframework.transaction.annotation.EnableTransactionManagement cannot be resolved
Run Code Online (Sandbox Code Playgroud)

Eyo*_*elD 5

您缺少spring-orm对象关系映射的依赖项。

只需将其导入到您的 pom 文件中

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.1.6.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)