I know I can load a file from src/test/resources with:
getClass().getResource(\"somefile\").getFile()
But how can I get the full path to th
Use the following to inject Hibernate with Spring in your unit tests:
@Bean
public LocalSessionFactoryBean getLocalSessionFactoryBean() {
LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean();
localSessionFactoryBean.setConfigLocation(new ClassPathResource("hibernate.cfg.xml"));
localSessionFactoryBean.setPackagesToScan("com.example.yourpackage.model");
return localSessionFactoryBean;
}
If you don't have the hibernate.cfg.xml
present in your src/test/resources
folder it will automatically fall back to the one in your src/main/resources
folder.