我试图让 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>
我错过了什么?
我不断收到错误:
No persistence units parsed from {classpath*:META-INF/persistence.xml}
最佳答案
理想情况下,packagesToScan 应该可以工作。
例如 -
<property name="packagesToScan" value="tutorials.core.models.entities"></property>
如果没有,那么您可以尝试这样的操作。 (根据文档,这是默认路径)
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"></property>
...
</bean>
之后你应该在 META-INF 中添加 persistence.xml(在 src/main/resources 下)
例如 -
<?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>
关于xml - 错误 : No persistence units parsed from {classpath*:META-INF/persistence. xml},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22394456/