網(wǎng)上看到在spring里配置sessionFactory的另一種寫法。
我一直用的配法
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://192.168.1.111:3306/comment_new"/>
<property name="password" value="root" />
<property name="username" value="root" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingDirectoryLocations">
<list>
<value>classpath:com/cocosily/comment/po</value>
</list>
</property>

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
</props>
</property>
</bean>
見到別人的另一種配法,直接保留hibernate.cfg.xml配置文件。然后通過屬性引入一下
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"/>
<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
</bean>
我一直用的配法



























見到別人的另一種配法,直接保留hibernate.cfg.xml配置文件。然后通過屬性引入一下



