In our integration tests we use configuration classes to only load the spring beans that we actually use. So, to initilaize our @Autowired Spring Data JpaRepository in our configuration class we could do something like this:
The problem with this solution is that there is a lot of boilerplate code in configuring the JpaRepositoryFactoryBean that makes this a little tedious to repeat, especially if you have more dependencies in your test that you need to initialize.
However, with generics and a static method we can make it a lot cleaner. With this static method we can create our JpaRepositoryFactoryBean with only a few parameters.
And this is how you would call it.
No comments:
Post a Comment