私は今夜しばらくの間、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]
さて、クラスが見つからず、例外がIllegal Argumentであり、ClassNotFoundなどではないのは不思議です。
これをサーブレットコンテキストで設定しました
<context:load-time-weaver/>
ルートコンテキストは次のとおりです。
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="emf"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
</bean>
<bean id="taskRepo" class="com.leandro.dao.GenericRepository">
<constructor-arg>
<value>com.leandro.models.Task</value>
</constructor-arg>
</bean>
emf Beanの生成に明らかに失敗しています。これは、次の行でGenericRepoに注入する必要があります。
@PersistenceContext
private EntityManager em;
public void setEntityManager(EntityManager em) {
this.em = em;
}
私はこれに一晩を費やしました、誰かが私が欠けているかもしれないものを知っていますか?
更新:要求に応じて、これは永続性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>