简体   繁体   中英

Spring Transaction with AspectJ

I'm having a problem with @Transaction in Spring. Basically, no transaction is created with the following message:

delaying identity-insert due to no transaction in progress

I posetd a full description of the problen in the Spring AOP forum

http://forum.springsource.org/showthread.php?132612-Transaction-management

Any suggestion would be appreciated!

Stefano

in your code you have defined the service like this:

@Service
@Configurable
public class ServiceImpl<T> implements Service<T> {
@Override
@Transactional
public T save(T entity) {
          ....
    }
}

I do not know why you use the @Configurable annotation. If you do not need them ( that is if you do not create an instance of this service via new ) , I would remove them.

The reason is that I remember that spring docu say that @Configurable enable injection, but it does not say anything about load time weaving support enabled by @Configurable

Found the solution.

The problem was in the configuratoin. I added two elements context:spring-configured and context:load-time-weaver that mean two different things. The first one activate AspectJ weaving (which I didn't understand), the second one activate AspectJ . 编织(我不了解),第二个激活AspectJ I think that these two elements don't work well together.

I decided to use compile time weaver and (after struggling a little bit...) I found that (obviously) external jars are not weaved with this configuration, simply because they have yet been built.

The easiest way to solve is to modify the configuration of the aspectj-maven-plugin (in POM.xml) adding under the configuration node:

<weaveDependencies>
<weaveDependency>
<groupId>GROUP-ID</groupId>
<artifactId>ARTIFACT-ID</artifactId>
</weaveDependency>
</weaveDependencies>
for every artifact you need to weave.

Now transactions work fine!

@Ralph: many thanks for your time!

Regards,

Stefano

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM