EnableTransactionManagement无法解析为某种类型

时间:2015-05-15 13:15:11

标签: java maven pom.xml

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...

}

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

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

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>4.1.6.RELEASE</version>
</dependency>

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

import org.springframework.transaction.annotation.EnableTransactionManagement;

这给了我以下错误:

The import org.springframework.transaction.annotation.EnableTransactionManagement cannot be resolved

3 个答案:

答案 0 :(得分:3)

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

只需将其导入您的pom文件

即可
<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.1.6.RELEASE</version>
</dependency>

答案 1 :(得分:0)

我不得不重新将jar文件添加到我项目中的库中,并且该类就在那里。谢谢你的帮助meriton

答案 2 :(得分:0)

如果您使用IntelliJ进行开发,请右键单击POM文件并添加为Maven项目。它应该解决这个问题。

enter image description here

enter image description here