In a JUnit test in my Spring application, I would like to insert a lot of data into the installation method, and then use it for testing. However, what was done in the method @Beforeseems to be rolled back after each test, even if I annotate the method with@Rollback(false)
Here is a simplified version of what I'm trying to do:
public class TestClass
{
@Autowired
MyService service;
@Before
public void setup()
{
if(service.getById(1) == null)
{
Thing thing = new Thing();
thing.setId(1);
service.create(new Thing(1))
}
}
}
I also tried using @BeforeClass, but this requires the method to be static and execute before the setter methods are called @Autowired, so I cannot access the services that I need to call when it @BeforeClassis executed.
@PostConstruct, ( , Hibernate ). , , , , , , , , , , , . @BeforeTransaction, , .