Spring3.1+springmvc3.1+hibernate3.5
jdk1.6          tomcat 6
运行报错:[异常信息]org.hibernate.MappingException: Unknown entity: com.tzw.entities.Baseamt经过自己百度,百度上的一些问题排查了一下,好像并没有发现什么错误,使用hbm.xml的形式进行配置,是可以的,但是一用packagesToScan就不行了,下面贴出配置文件代码<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:flex="http://www.springframework.org/schema/flex"
xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-2.5.xsd
 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"
default-lazy-init="true">
<!-- 导入资源文件 -->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:config.properties" />
</bean>
<!-- 包扫描,controller在mvc中有扫描 -->
<context:component-scan base-package="com.tzw">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!-- 加载数据库需要的四要素 --> <!-- 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
.....
</bean>
<!-- 配置SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<!-- 配置文件方式 -->
<!-- <property name="mappingDirectoryLocations"> <list> <value>classpath:/com/tzw/entities</value> 
</list> </property> -->
<!-- 注解方式 -->
<property name="packagesToScan">
<list>
<value>com.tzw.entities</value>
</list>
</property>
<!-- <property name="annotatedClasses"> <list> <value>com.tzw.entities.Baseamt</value> 
</list> </property> -->
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop><!-- 数据库方言 -->
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop><!--hibernate根据实体自动生成数据库表 -->
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop><!--是否显示sql语句 -->
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop><!--格式化显示sql语句 -->
<prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop><!-- 是否使用默认JDBC方式连接数据库(使用C3P0,false) -->
</props>
</property>
</bean> <!-- 配置一个事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 打开注解 -->
<context:annotation-config />
<!--开启事务注解 -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- 自动管理代理 -->
<aop:aspectj-autoproxy />
</beans>实体类中使用的注解也是jpa的引包工具用的eclipse,由于以前没怎么用过hibernate,自己想先试试,所以找了个最简单的类,没有主键啥的
然后是包结构:web.xml和一些mvc的配置就先不贴了,自己加hbm.xml配置是可以通的,也成功了,就是用注解就不行,不是很懂为什么会这样,也不知道是哪里写错了,望大神指点
有需要其他代码的,说一下我再贴,再次谢谢啦