小编Jay*_*kii的帖子

使用带传播属性的@Transactional时的编译错误

我使用教程开发了一个spring data jpa程序.然后通过添加一个新的类/方法来测试spring的@Transactional注释来修改它.

@Transactional
public void txnMethod() {
    repository.save(new Customer("First Customer",""));
    repository.save(new Customer("Second Customer",""));
    ...
}
Run Code Online (Sandbox Code Playgroud)

上面的代码正确编译和执行.然后我修改了代码以明确设置传播模式,如下所示,但这给了我一个编译错误 - "属性传播未定义注释类型Transactional"

@Transactional(propagation=Propagation.REQUIRED)
public void txnMethod() {
    repository.save(new Customer("First Customer",""));
    repository.save(new Customer("Second Customer",""));
    ...
}
Run Code Online (Sandbox Code Playgroud)

如何明确指定传播模式?以下是build.gradle中的依赖项.我使用的是春季启动版1.2.1.RELEASE

dependencies {
    compile("org.springframework.boot:spring-boot-starter-jdbc")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("org.springframework.boot:spring-boot-starter-web")
    compile ("org.springframework.boot:spring-boot-starter-tomcat")   
    compile("com.h2database:h2")                                      
    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")   
}
Run Code Online (Sandbox Code Playgroud)

transactional spring-boot

7
推荐指数
1
解决办法
3627
查看次数

标签 统计

spring-boot ×1

transactional ×1