Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 弹簧&x2B;Hibernate初始化错误:找不到类[<;providername>;]_Java_Spring_Hibernate_Entitymanager - Fatal编程技术网

Java 弹簧&x2B;Hibernate初始化错误:找不到类[<;providername>;]

Java 弹簧&x2B;Hibernate初始化错误:找不到类[<;providername>;],java,spring,hibernate,entitymanager,Java,Spring,Hibernate,Entitymanager,今晚,我一直在疯狂地尝试用java中的SpringMVC和Hibernate运行一个简单的项目。基本上,我从一个错误跌跌撞撞到另一个错误,但它们都是由于一个jar文件丢失的事实,我立即解决了这个问题,将依赖项添加到Maven中。在出现此错误之前,此操作一直有效: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emf' defined in ServletCo

今晚,我一直在疯狂地尝试用java中的SpringMVC和Hibernate运行一个简单的项目。基本上,我从一个错误跌跌撞撞到另一个错误,但它们都是由于一个jar文件丢失的事实,我立即解决了这个问题,将依赖项添加到Maven中。在出现此错误之前,此操作一直有效:

org.springframework.beans.factory.BeanCreationException: 
    Error creating bean with name 'emf' defined in ServletContext resource 
    [/WEB-INF/spring/root-context.xml]: Invocation of init method failed; 
    nested exception is java.lang.IllegalArgumentException: Cannot find class [Hibernate]
现在,奇怪的是,找不到类,异常是非法参数,而不是ClassNotFound或类似的东西

我在servlet上下文中设置了这个

<context:load-time-weaver/> 
我花了一整晚在这上面,有人知道我可能错过了什么吗

更新:根据请求,这是持久性xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="testmvc" transaction-type="RESOURCE_LOCAL">
        <provider>Hibernate</provider>
        <class>com.leandro.models.Task</class>
        <properties>
            <property name="hibernate.connection.username" value="***"/>
            <property name="hibernate.connection.password" value="***"/>
            <property name="hibernate.connection.url" value="jdbc:sqlserver://localhost\SQLEXPRESS;databaseName=CoveyTMM"/>
            <property name="hibernate.connection.driver_class" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://localhost\SQLEXPRESS;databaseName=CoveyTMM"/>
            <property name="javax.persistence.jdbc.user" value="***"/>
            <property name="javax.persistence.jdbc.password" value="***"/>
            <property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
        </properties>
    </persistence-unit>
</persistence>

冬眠
com.leandro.models.Task

正如@sgp15所建议的,问题出在持久性文件中。当我把它添加到问题中时,我注意到出了问题。我将指定提供程序的行更改为:

<provider>org.hibernate.ejb.HibernatePersistence</provider>
org.hibernate.ejb.HibernatePersistence
春天也能把它踩住


另外,我注意到还有其他错误,其中一个是由根上下文引起的。我只是删除了这一行:
因为我在tomcat上部署了Hibernate支持的JPA:

你的类路径中有Hibernate吗也可以发布persistence.xml吗?我认为这个异常与此有关。是的,在Maven依赖项中的类路径中有Hibernate。我首先手动添加了一些hibernate JAR,但随后将hibernate entitymanager添加到pom.xml中,并跨越了所有依赖项@sgp15我已经在问题中添加了持久性xml。
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="testmvc" transaction-type="RESOURCE_LOCAL">
        <provider>Hibernate</provider>
        <class>com.leandro.models.Task</class>
        <properties>
            <property name="hibernate.connection.username" value="***"/>
            <property name="hibernate.connection.password" value="***"/>
            <property name="hibernate.connection.url" value="jdbc:sqlserver://localhost\SQLEXPRESS;databaseName=CoveyTMM"/>
            <property name="hibernate.connection.driver_class" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://localhost\SQLEXPRESS;databaseName=CoveyTMM"/>
            <property name="javax.persistence.jdbc.user" value="***"/>
            <property name="javax.persistence.jdbc.password" value="***"/>
            <property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
        </properties>
    </persistence-unit>
</persistence>
<provider>org.hibernate.ejb.HibernatePersistence</provider>