spring bean的配置

spring bean的配置 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<!-- 设置数据源-->
<bean id="datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  <property name="driverClass">
    <value>com.mysql.jdbc.Driver</value>
   </property>
  <property name="jdbcUrl">
     <value>jdbc:mysql://localhost/test</value></property>
  <property name="user"><value>root</value></property>
  <property name="password"><value>admin</value></property>
  <property name="maxPoolSize"><value>20</value></property>
  <property name="minPoolSize"><value>5</value></property>
  <property name="initialPoolSize"><value>1</value></property>   
 
</bean>
 
  <!-- 定义Hibernate的SessionFactory -->
  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <!-- 由Spring依赖注入DataSource-->
    <property name="dataSource">
      <ref local="datasource"/>
    </property>
    <!-- 列出全部映射文件-->
    <property name="mappingResources">
       <list>
          <value>com/mydemo/model/Userinfo.hbm.xml</value>
       </list>
     
    </property>
    <!--配置Hibernate属性 -->  
    <property  name="hibernateProperties">
      <props>
        <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
        <prop key="show_sql">true</prop>
        <prop key="hibernate.hbm2ddl.auto">update</prop>
      </props>
    </property>
   
  </bean>
 
  <!-- 配置事务管理器-->
  <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
      <ref local="sessionFactory"/>
    </property>
  </bean>
 
  <!-- 配置事务拦截器
  <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
     <property name="transactionManager">
       <ref local="transactionManager"/>
     </property>
    <property name="transactionAttributes">
      <props>
        <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
        <prop key="*">PROPAGATION_REQUIRED</prop>
      </props>
    </property>
  </bean>-->
 
 
  <!--实现类 -->
  <bean id="userDaoImpl" class="com.mydemo.dao.impl.UserDaoImpl">
     <property name="sessionFactory">
       <ref local="sessionFactory"/>
     </property>
  </bean>
 
  <!--service定义 -->
 
  <bean id="userService" class="com.mydemo.service.DaoService">    
    <property name="userDao">
      <ref local="userDaoImpl"/>
    </property>
   
  </bean>

 

 

</beans>

你可能感兴趣的:(spring,Hibernate,mysql,bean,Class,encoding)