spring中jdbc.properties配置文件用法


jdbc.properties代码:

 copy
 
  1. jdbc.driverClassName=oracle.jdbc.driver.OracleDriver  
  2. jdbc.url=jdbc:oracle:thin:@10.10.1.1:1521:ORCL  
  3. jdbc.username=test  
  4. jdbc.password=test  

applicationContext.xml代码:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xmlns:aop="http://www.springframework.org/schema/aop"  
  5.     xmlns:tx="http://www.springframework.org/schema/tx"  
  6.     xmlns:context="http://www.springframework.org/schema/context"  
  7.     xsi:schemaLocation="http://www.springframework.org/schema/beans  
  8.         http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  9.         http://www.springframework.org/schema/context  
  10.         http://www.springframework.org/schema/context/spring-context-2.5.xsd  
  11.         http://www.springframework.org/schema/aop  
  12.         http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
  13.         http://www.springframework.org/schema/tx  
  14.         http://www.springframework.org/schema/tx/spring-tx-2.5.xsd ">  
  15.   
  16.     <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  17.         <property name="locations">  
  18.            <list>  
  19.                  <!--个人目录不同,仅供参考-->
  20.                  <value>/WEB-INF/classes/jdbc.properties</value>  
  21.            </list>  
  22.         </property>  
  23.     </bean>  
  24.   
  25.     <bean id="dataSource"  
  26.         class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
  27.         <property name="driverClassName"  
  28.             value="${jdbc.driverClassName}">  
  29.         </property>  
  30.         <property name="url"  
  31.             value="${jdbc.url}">  
  32.         </property>  
  33.         <property name="username" value="${jdbc.username}"></property>  
  34.         <property name="password" value="${jdbc.password}"></property>  
  35.     </bean>  
  36.     <bean id="sessionFactory"  
  37.         class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  38.         <property name="dataSource">  
  39.             <ref bean="dataSource" />  
  40.         </property>  
  41.         <property name="hibernateProperties">  
  42.             <props>  
  43.                 <prop key="hibernate.dialect">  
  44.                     org.hibernate.dialect.OracleDialect  
  45.                 </prop>  
  46.             </props>  
  47.         </property>  
  48.         <property name="mappingResources">  
  49.             <list>  
  50.                 <value>com/xy6/form/LoginForm.hbm.xml</value>  
  51.             </list>  
  52.         </property>  
  53.     </bean>  
  54.     <!-- 指定事务管理器类,将sessionFactory注入,让该事务管理器具有打开和关闭事务的能力 -->  
  55.     <bean id="transactionManager"  
  56.         class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  57.         <property name="sessionFactory" ref="sessionFactory"></property>  
  58.     </bean>  
  59.     <!-- 为事务管理器类指定匹配器,通过用name指定的匹配字符串进行对对应的方法进行打开和关闭事务 -->  
  60.     <tx:advice id="txAdvice" transaction-manager="transactionManager">  
  61.        <tx:attributes>  
  62.            <tx:method name="save*" propagation="REQUIRED" />  
  63.            <tx:method name="delete*" propagation="REQUIRED" />  
  64.            <tx:method name="modify*" propagation="REQUIRED" />  
  65.            <tx:method name="deploy*" propagation="REQUIRED" />  
  66.            <tx:method name="*" read-only="true" />  
  67.        </tx:attributes>  
  68.     </tx:advice>  
  69.   
  70.     <!-- 为事务管理器类指定进行匹配的范围,到指定的地方通过匹配器字符串进行筛选,对应上后为该方法打开和关闭事务 -->  
  71.     <aop:config proxy-target-class="true">  
  72.        <aop:pointcut id="managerOperation" expression="execution(* com.xy6.dao.*.*(..))" />  
  73.        <aop:advisor advice-ref="txAdvice" pointcut-ref="managerOperation" />  
  74.     </aop:config>  
  75.   
  76.      <!-- 该 BeanPostProcessor 将自动对标注 @Autowired 的 Bean 进行注入 -->  
  77.     <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>  
  78.   
  79.     <!-- 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入 -->  
  80.     <context:component-scan base-package="com.xy6"/>  
  81.   
  82.     <!-- spring转发 -->  
  83.     <bean name="/login" class="com.xy6.action.LoginAction">  
  84.     </bean>  
  85.   
  86.     <bean id="loginAction" class="com.xy6.action.LoginAction"></bean>  
  87.     <bean id="loginService" class="com.xy6.service.impl.LoginServiceImpl"></bean>  
  88.     <bean id="loginDAO" class="com.xy6.dao.impl.LoginDaoImpl">  
  89.         <property name="sessionFactory" ref="sessionFactory"></property>  
  90.     </bean>  
  91. </beans>  

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值