Skip to content

@EnableTransactionManagement proxyTargetClass not control by spring.aop.proxyTargetClass #8434

Closed

Description

@Dreampie

if use @Transactional,and set spring.aop.proxyTargetClass=false, this class also create by cglib not jdk proxy,you must config @EnableTransactionManagement(proxyTargetClass=false) to use jdk proxy with @Transactional

@Service
public class DemoServiceImpl implements DemoService {

    @Transactional
    public void test() {
        System.out.println("Test");
    }
}

And @EnableTransactionManagement proxyTargetClass default value is false, why spring boot change to true?

Activity

  1. added
    status: waiting-for-triage
    on Feb 28, 2017
  2. philwebb commented on Feb 28, 2017

    @philwebb
    Member

    This was changed in 1.4 (see #5423). We've generally found cglib proxies less likely to cause unexpected cast exceptions.

  3. added
    status: invalid
    and removed
    status: waiting-for-triage
    on Feb 28, 2017
  4. philwebb commented on Feb 28, 2017

    @philwebb
    Member

    Sorry, I misunderstood your initial comment. You're saying you add spring.aop.proxyTargetClass=false to application.properties but we ignore that and use cglib regardless?

  5. added
    status: waiting-for-feedback
    status: waiting-for-triage
    and removed
    status: invalid
    on Feb 28, 2017
  6. removed
    status: waiting-for-feedback
    on Feb 28, 2017
  7. mdeinum commented on Mar 5, 2017

    @mdeinum
    Contributor

    the spring.aop.proxy-target-class is only used to toggle the configuration in AopAutoConfiguration for other proxy creation it is being ignored, like for @EnableTransactionManagement and the configuration of the PersistenceExceptionTranslationPostProcessor.

    I noticed this during introducing Spring Boot into a project which used quite a lot of final classes (or classes with final methods). I ran into it in those areas but maybe there are a few more (like JMX for instance).

  8. added
    type: bug
    and removed
    status: waiting-for-triage
    on Mar 6, 2017
  9. added this to the 1.4.6 milestone on Mar 6, 2017
  10. snicoll commented on Mar 13, 2017

    @snicoll
    Member

    While we're working on it, we may want to share that thing in its own auto-configuration and order that in a sensible manner, see #8587

  11. added a commit that references this issue on Mar 17, 2017
    b20dff1
  12. snicoll commented on Mar 17, 2017

    @snicoll
    Member

    @philwebb I've worked on a solution in b20dff1 that is a bit larger than what is foreseen here. I am not sure if that belongs to 1.4 but a couple of thoughts:

    1. Our default for this is CGLIB which basically upgrade the whole context to go CGLIB. IMO we should change the default of spring.aop.proxy-target-class to true
    2. So far we only enabled transaction management when a DataSource is present. That led to the Neo4j problem (Auto-configure @EnableTransactionManagement with Neo4J #8587) but any data tech that supports PlatformTransactionManager is also affected. IMO it makes more sense to enable it once such a bean is found in the context

    I think that 1. is pretty bad because we won't be able to change it in 1.4 or 1.5 and currently we're doing that effectively as soon as you use @Transactional in your app.

  13. self-assigned this
    on Mar 20, 2017
  14. added
    for: team-attention
    on Mar 20, 2017
  15. modified the milestones: 1.5.3, 1.4.6 on Mar 31, 2017
  16. removed
    for: team-attention
    on Mar 31, 2017
  17. self-assigned this
    on Mar 31, 2017
  18. added 2 commits that reference this issue on Apr 3, 2017
    db33a75
    0163731
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

type: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions