src/beans.xml

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?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:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-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
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<!-- Spring整合Hibernate -->
	
<!-- 支付annotation -->
<context:annotation-config/>
	
<!-- 组件:扫描com.zfxx包下的所有的类:service和dao,实例化@Component声明的组件 -->
<context:component-scan base-package="com.InsuranceBusiness"></context:component-scan>

<!-- 第一步:数据源连接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  <property name="url" value="jdbc:mysql://localhost:3306/数据库sql?characterEncoding=UTF-8"/>
  <property name="username" value="root"/>
  <property name="password" value="root"/>
</bean>  
  
<!-- 将数据源注入到SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    
    <!-- 扫描实体类 -->
    <property name="packagesToScan">
      <list>
        <value>com.InsuranceBusiness.model</value>
      </list>
    </property>
    <property name="hibernateProperties">
    	<props>
    		<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
    		<prop key="hibernate.show_sql">true</prop>
    		<prop key="hibernate.hbm2ddl.auto">update</prop>
    		<prop key="hibernate.format_sql">true</prop>
    		<prop key="hibernate.current_session_context_class">thread</prop>
    	</props>
    </property>
</bean>

<!-- 声明式事务管理:SessionFactory注入到事务管理中 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!-- 事务管理:必须掌握。不需要在每个方法上@Transaction -->
<tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
后面还有 11 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。