I test the following DAO with JUnit:
@Repository public class MyDao { @Autowired private SessionFactory sessionFactory; // Other stuff here }
I had same problem with Spring Boot 2.1.1 and JUnit 4 just added those annotations:
@RunWith( SpringRunner.class ) @SpringBootTest
and all went well.
For Junit 5:
@ExtendWith(SpringExtension.class)
source