mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Use @Autowired EntityManager in Jupiter JPA tests
Switching from @PersistenceContext to @Autowired for dependency injection in tests allows such tests to participate in AOT processing. Note, however, that we still have TestNG-based tests that use @PersistenceContext — for example, AbstractEjbTxDaoTestNGTests. See gh-29122 See gh-31442 See gh-33414
This commit is contained in:
+1
-2
@@ -19,7 +19,6 @@ package org.springframework.test.context.orm.jpa;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -48,7 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@Sql(statements = "insert into person(id, name) values(0, 'Jane')")
|
||||
class JpaEntityListenerTests {
|
||||
|
||||
@PersistenceContext
|
||||
@Autowired
|
||||
EntityManager entityManager;
|
||||
|
||||
@Autowired
|
||||
|
||||
+1
-2
@@ -17,7 +17,6 @@
|
||||
package org.springframework.test.context.orm.jpa;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -44,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@Sql(statements = "insert into person(id, name) values(0, 'Jane')")
|
||||
class JpaPersonRepositoryTests {
|
||||
|
||||
@PersistenceContext
|
||||
@Autowired
|
||||
EntityManager em;
|
||||
|
||||
@Autowired
|
||||
|
||||
Reference in New Issue
Block a user