0

I use annotation to record the operation log. But now it is rolled back by @Transactional. And I use the @Order annotation but it does not work.

Here is the xml transactional config

<bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>

and this is the operation annotation

@Target({ java.lang.annotation.ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface Operation {
    public abstract Operator operator();

    public abstract String operation();

    public abstract String desc();

    public abstract OperationLevel level();
}

and this is usage

my point cut

now it's working, but when an exception happens in createBuy method, @Before rollback too.

tkruse
  • 10,222
  • 7
  • 53
  • 80
jack chen
  • 1
  • 1
  • 3
    Ofcourse it won't work. It participates in the same transaction and if that fails it will rollback... If you want to log that stuff regardless of the outcome of the transaction you have to use `REQUIRES_NEW` on the `createAuditLog` method, that will ensure that runs in a separate non-related transaction. – M. Deinum May 12 '17 at 06:10
  • oh thanks! it`s work! In fact i create another project, the @Order annotation is work too, but this project is not work.Whatever thank you! – jack chen May 12 '17 at 06:22

0 Answers0