如题所述,想要一个spring2.5+hibernate配置文件的最新写法参考下

解决方案 »

  1.   

    网上有spring2.5的文档,你去下一个,里面写的很清楚的,
      

  2.   

    配置数据源
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/spring?useUnicode=true&amp;characterEncoding=utf8"/>
    <property name="username" value="root"/>
    <property name="password" value="123456"/>
    <property name="maxActive" value="100"/>
    <property name="maxIdle" value="30"/>
    <property name="maxWait" value="1000"/>
    <property name="defaultAutoCommit" value="true"/>
    <property name="removeAbandoned" value="true"/>
    <property name="removeAbandonedTimeout" value="60"/>
    <property name="logAbandoned" value="true"/>
    </bean><!-- 配置hibernate的SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <!-- 依赖注入SessionFactory所需要的DataSource -->
    <property name="dataSource" ref="dataSource"/>
    <!-- 加载所有的映射文件 -->
    <property name="mappingResources">
    <!-- 下面列出所有的持久化映射文件 -->
    <list>
    <value>web/model/news/News.hbm.xml</value>
    <value>web/model/news/User.hbm.xml</value>
    <value>web/model/news/Review.hbm.xml</value>
    <value>web/model/news/Poster.hbm.xml</value>
    <value>web/model/news/Category.hbm.xml</value>
    </list>
    </property>
    <!-- 指定hibernate的属性 -->
    <property name="hibernateProperties">
    <props>
    <!-- 指定hibernate使用的数据库方言 org.hibernate.dialect.MySQLDialect-->
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
    </bean>以下是配置事务
    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
    </bean> <tx:advice id="txAdvice" transaction-manager="txManager">
    <!-- the transactional semantics... -->
    <tx:attributes>
    <!-- all methods starting with 'get' are read-only -->
    <tx:method name="get*" read-only="true"/>
    <tx:method name="load*" read-only="true"/>
    <tx:method name="list*" read-only="true"/>
    <!-- other methods use the default transaction settings (see below) -->
    <tx:method name="*"/>
    </tx:attributes>
    </tx:advice> <!-- ensure that the above transactional advice runs for any execution
    of an operation defined by the FooService interface com.dtb.web.impl-->
    <aop:config>
    <aop:pointcut id="webServiceOperation" expression="execution(这里是事务的目录)"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="webServiceOperation"/>
    </aop:config>
      

  3.   


    如果不用AOP控制的话。。应该怎么写呢?
      

  4.   

    使用注解
    <bean id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${driverClassName}" />
    <property name="url" value="${url}" />
    <property name="username" value="${username}" />
    <property name="password" value="${password}" />
    <property name="initialSize" value="${initialSize}" />
    <property name="maxActive" value="${maxActive}" />
    <property name="maxIdle" value="${maxIdle}" />
    <property name="minIdle" value="${minIdle}" />
    <property name="maxWait" value="${maxWait}" />
    </bean>
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="mappingResources">
    <list>
    <value>cn/itcast/domain/Person.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <value>
    hibernate.dialect=org.hibernate.dialect.MySQLDialect
    hibernate.hbm2ddl.auto=update
    hibernate.show_sql=true
    hibernate.format_sql=true
    </value>
    </property>
    </bean>
    <bean id="txManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <tx:annotation-driven transaction-manager="txManager" />