相关文章推荐
I find it extremely hard to write @SpringBootTest if you use @ComponentScan and Jpa repositories. Can someone advice? This should be super-trivial stuff, but it's not documented anywhere.



and one of discovered Configuration classes has:



Now I want to create test , which will enable ideally just a subset of JPA repositories AND exactly nothing else, unless I tell so. Namely, no configuration from production source code. This seems to be close to impossible to express. This is where I was able to get:




so this configuration produces error

java.lang.IllegalArgumentException: Not a managed type ...my jpa repository class

which probably means, that jpa package isn't among autoconfigured packages. No idea how to add it if it's even possible.

OK, another approach. Some sources recommends this:



but this one fails with caused by: java.lang.IllegalArgumentException: At least one JPA metamodel must be present!

Any hints?
OK, after a lot of searching (in vain) and even more trying, I think I have answer.

To recap:

you have main class (thanks @Bhushan Shinde):



and some configuration:



So to use SpringBootTest and configure everything from scratch for test, ignoring production configurations, you go:



maybe there is something extra here, but after day of googling & trying this is good enough for me.
contact us | advertise |
 
推荐文章