简体   繁体   中英

Spring autowiring dependencies after each junit test

I'm having a problem whereby spring is re-creating my beans and re-auto wiring after each junit test has been run. I only want spring to do this once, on the post construct of the test class, which is what I've configured it to do.

I've also tried setting the @DirtiesContext class mode to AFTER_CLASS, but this still didn't solve the issue.

Any ideas?

Cheers.

You can create a class:

@SpringJUnitConfig(classes = {ConfigClassOne.class, ConfigClassTwo.class, ConfigClassThree.class})
public abstract class ModelTest {}

and extend it in the test classes. Beans will not be recreated because the application contexts are already mentioned in the annotation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM