How to validate which transaction mode is being used? (Aspectj / Proxy)

Asked

Viewed 18 times

0

At the moment, we are building a module in Spring Boot that uses a legacy settings, built on top of Spring MVC and has many configurations (XML and classes).

After a few weeks, we were able to make Spring Boot compatible with the legacy settings, but we couldn’t validate if, in fact, Aspectj is working as expected.

And why do I say that?

We observe that during configuration, within the TransactionManagementConfigurationSelector (in the code below), we are receiving the adviceModes of PROXY and ASPECTJ:

/**
 * Returns {@link ProxyTransactionManagementConfiguration} or
 * {@code AspectJ(Jta)TransactionManagementConfiguration} for {@code PROXY}
 * and {@code ASPECTJ} values of {@link EnableTransactionManagement#mode()},
 * respectively.
 */
@Override
protected String[] selectImports(AdviceMode adviceMode) {
    switch (adviceMode) {
        case PROXY:
            return new String[] {AutoProxyRegistrar.class.getName(),
                    ProxyTransactionManagementConfiguration.class.getName()};
        case ASPECTJ:
            return new String[] {determineTransactionAspectClass()};
        default:
            return null;
    }
}

This particular case is even more curious, since during debugging we receive twice ASPECTJ and once proxy at the end of the settings. It seems that the Aspectj settings of the legacy are being applied, but something is also configuring the advice mode Proxy.

After further investigation, we found the originator of the Proxy warning mode, which is the TransactionAutoConfiguration, more specifically theTransactionAutoConfiguration.EnableTransactionManagementConfiguration.CglibAutoProxyConfiguration.class.

The application of the following exclusion prevented the advice mode PROXY was configured in TransactionManagementConfigurationSelector, but we are not 100% sure that this will not affect the application at some point:

@SpringBootApplication (exclude = TransactionAutoConfiguration.class)

Given the fact that we have only Aspectj configured in our application, and this setting is also applying Proxy, there is a way to validate which mode is being used during a transaction, and if possible, which classes are using Proxy and which are using Aspectj?

1 answer

0


After all this time I forgot even to answer.

Programmatically I found no way to validate which transaction mode is enabled.

The only way we found to validate this was to change the log level for the Spring classes, and validate the package being logged in during transactions. The PROXY and ASPECT packages are different, so we were able to visually validate that the correct transaction was being used.

It’s not the best solution in the world, it’s totally error-prone, and we don’t think it’s feasible to write a test for log validation on your.

For now we will accept this solution anyway, and perhaps one day we will return to this issue.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.