@EnableTransactionManagement in Spring Boot

后端 未结 6 1780
你的背包
你的背包 2020-12-07 16:58

Is @EnableTransactionManagement required in Spring Boot? I did some research. Some folks say you don\'t need it, as Spring Boot has it already enabled, others s

6条回答
  •  天命终不由人
    2020-12-07 17:10

    In the class org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration, there is such code(Spring Boot 1.5+):

        @Configuration
        @EnableTransactionManagement(proxyTargetClass = false)
        @ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "false", matchIfMissing = false)
        public static class JdkDynamicAutoProxyConfiguration {
    
        }
    
        @Configuration
        @EnableTransactionManagement(proxyTargetClass = true)
        @ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "true", matchIfMissing = true)
        public static class CglibAutoProxyConfiguration {
    
        }
    

    The default is spring.aop.proxy-target-class=true, enabling CGLIB proxy by default. If you want to use JDK proxy, set spring.aop.proxy-target-class=false instead.

提交回复
热议问题