---
title: "spring 扫描 hibernate 注解：packagesToScan"
author: "submaze"
date: "2014-08-02T15:37:10Z"
tags: []
categories: ["企业架构"]
slug: "spring-hibernate-packagestoscan"
draft: false
lastmod: "2014-08-02T15:39:23Z"
id: 2099642
url: "https://submaze.iteye.com/blog/2099642"
---

这几天在搭建一个新架构，引用了spring 2.5.6中新加的特性，就是自动扫描Class的hibernate映射文件。
我的class都在com.pplus.model这个包里，注意
配置参数
org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean

<property name="packagesToScan">
</property>


```xml


<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="namingStrategy">
           <bean class="org.hibernate.cfg.ImprovedNamingStrategy"/>
        </property>
        <property name="hibernateProperties">
            <value>
                hibernate.dialect=${hibernate.dialect}
                hibernate.query.substitutions=true 'Y', false 'N'
                hibernate.cache.use_second_level_cache=true
                hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
            </value>
            <!-- Turn batching off for better error messages under PostgreSQL -->
            <!-- hibernate.jdbc.batch_size=0 -->
        </property>
        <property name="packagesToScan">
            <list>
              <value>com.pplus.*</value>  <!--若写成com.pplus.model.* 则映射不到，还没有来得及看源代码 -->
            </list>
         </property>
    </bean>


```