I would like to use the transactions performed by aspects in spring-boot, but so far I have basically found help for more "normal" installations ...
What have I managed to configure so far?
I have annotations for the main class:
@SpringBootApplication @EnableTransactionManagement(mode=AdviceMode.ASPECTJ) @EnableLoadTimeWeaving(aspectjWeaving=AspectJWeaving.ENABLED)
And this is in my properties:
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
I am running the application with the spring-tool and aspectj-weaver java agents, and I can see the aspects in stacktrace where I used @Transactional , at least it works.
Besides that, which is really strange, the problem only started after I added the second entity - at first it worked without problems, but now I have this error:
org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
From what I noticed, beanFactory is null when invokeWithinTransaction is executed on TransactionAspectSupport - but it is set during bean creation (and from what I saw when debugging, when beanFactory null TransactionAspectSupport does not start the transaction because it cannot receive the TransactionManager ) I assume that the TransactionAspectSupport instance is not a bean being created at some point, and this may be causing my problem (but then how and why?)?
Update:
From what I noticed, @Transactional handled by AnnotationTransactionAspect in one case, but JtaAnnotationTransactionAspect in another.
Any ideas what I am missing? Perhaps some kind of magical property that I should set?
Oh, and here are my dependencies, if that matters:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>18.0</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.4</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-instrument</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.8.7</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.8.7</version> </dependency> </dependencies>