003醫療項目-關於的問題

 

項目結構以下:java

場景以下:spring整合數據庫。spring

在applicationontext.xml中配置以下:數據庫

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    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-3.1.xsd 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.1.xsd 
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ">

<!-- 加載配置文件 -->
<context:property-placeholder location="classpath:db.properties"/>

<!-- 數據庫鏈接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
       <property name="driverClassName" value="${jdbc.driver}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <!-- 開發階段建議最大鏈接數據儘可能少,夠用便可 -->
        <property name="maxActive" value="${jdbc.maxActive}"/>
        <property name="maxIdle" value="${jdbc.maxIdle}"/>
</bean>

<!-- 事務管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <!-- 數據源 -->
    <property name="dataSource" ref="dataSource"/>
</bean>

<!-- 通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
  <tx:attributes>
     <!-- 傳播行爲 -->
    <tx:method name="save*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
    <tx:method name="insert*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
    <tx:method name="delete*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
    <tx:method name="update*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
    <tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
    <tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
  </tx:attributes>
</tx:advice>

<!-- 切面 -->
<aop:config proxy-target-class="true">
  <aop:advisor advice-ref="txAdvice"
  pointcut="execution(* yycg.*.service.impl.*.*(..))"/>
</aop:config>
</beans>

上面中的apache

<!-- 加載配置文件 --> <context:property-placeholder location="classpath:db.properties"/>很奇怪,這裏的db.properties明明在src/main/resources目錄下。
爲何這裏直接寫classpath就能夠了。

緣由以下:
你仔細看config的圖標。這個圖標表示該目錄是源文件夾。編譯後源文件夾的非java文件會被copy到classes目錄。 你能夠右鍵 選擇 build path ,而後能夠把一些目錄加入成爲源文件夾,或者移出源文件夾。
不管有幾個源文件夾,最後都會被加到classes目錄裏。



因此咱們打開項目的classes目錄:

就能夠看到這麼文件。
相關文章
相關標籤/搜索