当前位置: 代码迷 >> 综合 >> spring配置文件,常用配置说明
  详细解决方案

spring配置文件,常用配置说明

热度:58   发布时间:2023-10-26 09:01:11.0
        <!-- 将静态文件中的内容加载到配置中 --><context:property-placeholder location="classpath:db.properties"/><!-- 组建扫描,将用使用component、controller、service、repository、controllerAdvice等标注的注解扫描到容器中 --><context:component-scan base-package="com.nxmu.spring.hibernate"></context:component-scan><!-- 配置数据库连接池 --><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="user" value="${jdbc.user}"></property><property name="password" value="${jdbc.password}"></property><property name="jdbcUrl" value="${jdbc.url}"></property><property name="driverClass" value="${jdbc.driverClass}"></property><property name="initialPoolSize" value="${jdbc.initialPoolSize}"></property><property name="maxPoolSize" value="${jdbc.maxPoolSize}"></property></bean><!-- 配置hibernate支持 --><bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"><property name="dataSource" ref="dataSource"></property><property name="configLocation" value="classpath:hibernate.cfg.xml"></property><!-- <property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.format_sql">true</prop><prop key="hibernate.hbm2ddl.auto">update</prop></props></property> --><property name="mappingLocations" value="classpath:com/nxmu/spring/hibernate/entities/*.hbm.xml"></property></bean><!-- 配置hibernate事物管理 --><bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory"></property></bean><!-- 配置事务管理器 --><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="get*" read-only="true"/><tx:method name="find*" read-only="true"/><tx:method name="purchese" propagation="REQUIRES_NEW"/><tx:method name="*"/></tx:attributes></tx:advice><!-- 配置需要事务管理的方法 --><aop:config><aop:pointcut expression="execution(* com.nxmu.spring.hibernate.service.*.*(..))" id="servicePoint"/><aop:advisor advice-ref="txAdvice" pointcut-ref="servicePoint"/></aop:config>

  相关解决方案