mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-23 22:59:03 +00:00
Document AOT workaround for @PersistenceContext & @PersistenceUnit in tests
Although @PersistenceContext and @PersistenceUnit are still not
supported in tests running in AOT mode, as of Spring Framework 7.0,
developers can inject an EntityManager or EntityManagerFactory into
tests using @Autowired instead of @PersistenceContext and
@PersistenceUnit, respectively.
See commit 096303c477
See gh-33414
Closes gh-31442
This commit is contained in:
@@ -43,6 +43,16 @@ alternative, you can set the same property via the
|
||||
xref:appendix.adoc#appendix-spring-properties[`SpringProperties`] mechanism.
|
||||
====
|
||||
|
||||
[TIP]
|
||||
====
|
||||
JPA's `@PersistenceContext` and `@PersistenceUnit` annotations cannot be used to perform
|
||||
dependency injection within test classes in AOT mode.
|
||||
|
||||
However, as of Spring Framework 7.0, you can inject an `EntityManager` or
|
||||
`EntityManagerFactory` into tests using `@Autowired` instead of `@PersistenceContext` and
|
||||
`@PersistenceUnit`, respectively.
|
||||
====
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
The `@ContextHierarchy` annotation is not supported in AOT mode.
|
||||
|
||||
Reference in New Issue
Block a user