[转]用jpa创建web项目,报错:No persistence units parsed from {classpath*:META-INF/persistence.xml}

原文地址:http://blog.sina.com.cn/s/blog_6826662b01015opk.html

最近做一个web项目用到了Spring+JPA,由于没有正确配置persistence.xml的文件路径,导致出现如下错误:

No persistence units parsed from {classpath*:META-INF/persistence.xml}

查找原因,原来在web工程文件夹下,本来有一个 META-INF 文件夹,但这个文件夹是和 WEB-INF 目录同级:

Spring+JPA:No <wbr>persistence <wbr>units <wbr>parsed <wbr>from <wbr>{classpath*:META-INF/persistence.xml}

JPA的persistence.xml配置文件不能放到这个META-INF文件夹下,而是要放到 WEB-INF/classes/META-INF文件夹下:

Spring+JPA:No <wbr>persistence <wbr>units <wbr>parsed <wbr>from <wbr>{classpath*:META-INF/persistence.xml}

这样再启动tomcat,访问web工程就不会出现上述错误了。

posted @ 2016-01-26 14:47  dirgo  阅读(935)  评论(0编辑  收藏  举报