2013-05-02 51 views
1

我試圖在我現有的Spring 3 MVC + Spring 3 security項目中設置Hibernate 3.6。不過,我不斷收到java.lang.ClassNotFoundExceptionHibernateUtil類 - 符合return new Configuration().configure().buildSessionFactory();Spring 3項目中的Hibernate基本配置 - 類未找到異常

我的項目結構如下:

enter image description here

hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE hibernate-configuration PUBLIC 
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration> 
    <session-factory> 
     <property name="hibernate.bytecode.use_reflection_optimizer">false</property> 
     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
     <property name="hibernate.connection.password">password</property> 
     <property name="hibernate.connection.url">jdbc:mysql://localhost:3049/test</property> 
     <property name="hibernate.connection.username">root</property> 
     <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 
     <property name="show_sql">true</property> 
     <mapping resource="./DBUser.hbm.xml"></mapping> 
    </session-factory> 
</hibernate-configuration> 

DBUser.hbm.xml

<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
<hibernate-mapping> 
    <class name="../src/main/java/user/DBUser" table="DBUSER"> 
     <id name="userId" type="int"> 
      <column name="USER_ID" precision="5" scale="0" /> 
      <generator class="assigned" /> 
     </id> 
     <property name="username" type="string"> 
      <column name="USERNAME" length="20" not-null="true" /> 
     </property> 
     <property name="createdBy" type="string"> 
      <column name="CREATED_BY" length="20" not-null="true" /> 
     </property> 
     <property name="createdDate" type="date"> 
      <column name="CREATED_DATE" length="7" not-null="true" /> 
     </property> 
    </class> 
</hibernate-mapping> 

而且pom.xml文件的相關部分:

<!-- Hibernate + MySQL --> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <version>5.1.9</version> 
     </dependency> 

     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-core</artifactId> 
      <version>3.6.3.Final</version> 
     </dependency> 

編輯:我已經貼here the stack trace。把它放在這裏太長了,因爲這會讓這個帖子感到困惑。

我真的很高興,如果有人能幫助我設置這個東西,因爲我不知道,爲什麼找不到那個類。

+1

堆棧跟蹤將有所幫助。 – Jeshurun 2013-05-02 18:42:48

+0

我認爲你有更多的依賴添加到你的POM中:http://mvnrepository.com/artifact/org.hibernate/hibernate-core/3.6.3.Final(這個神器取決於...) – 2013-05-02 18:56:24

回答

1

它看起來像你缺少javaassist庫。下載javaassist jar並將其添加到您的類路徑中。

+0

你完全正確!我沒有注意到它! – Dworza 2013-05-02 18:54:45

1

你的類名應該是包路徑Hibernate的POJO中DBUser.hbm.xml,e.g:

user/DBUser 

你的映射資源並不需要在路徑./