spring - hibernate load *.hbm.xml from classpath resource

后端 未结 5 561
野的像风
野的像风 2021-01-19 15:04

I have some hbm.xml files in classpath resource located in src/main/resources maven\'s folder. I used spring\'s LocalSessionFactoryBean to load these files with the followin

5条回答
  •  臣服心动
    2021-01-19 15:39

    If you are loading your Spring application context from a webapp, you might see an error like this:

    SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: ServletContext resource [/hibernate.cfg.xml] cannot be resolved to URL because it does not exist
    

    The solution is to explicitly tell Spring to load the configuration from the classpath like so:

    classpath:mypath/myfile.xml
    

提交回复
热议问题