错误:未从 {classpath*:META-INF/persistence.xml} 解析出持久性单元

mar*_*cks 5 xml spring hibernate

我试图让 Spring 和 Hibernate 在没有 persistence.xml 的情况下工作。我正在我的 context.xml 文件上设置我的实体包扫描器,如下所示:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"/>
    <property name="hibernateProperties" ref="hibernatePropertiesConfigurer"/>
    <property name="packagesToScan" value="com.therubythree.simpleapi.entities"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

我不断收到错误:

No persistence units parsed from {classpath*:META-INF/persistence.xml}
Run Code Online (Sandbox Code Playgroud)

Man*_*jee 5

理想情况下,packagesToScan 应该可以工作。

前任 -

<property name="packagesToScan" value="tutorials.core.models.entities"></property>
Run Code Online (Sandbox Code Playgroud)

如果没有,那么你可以尝试这样的事情。(根据文档,这是默认路径)

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"></property>
    ...
</bean>
Run Code Online (Sandbox Code Playgroud)

之后,您应该在 META-INF(在 src/main/resources 下)中添加 persistence.xml

前任 -

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
<persistence-unit name="studentPersistenceUnit" transaction-type="RESOURCE_LOCAL" >
<class>tutorials.models.entities.Student</class>
</persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud)