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:
parent
2f47efe2d3
commit
096303c477
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue