的问题" type="hidden"/>

003医疗项目-关于的问题


 

项目结构如下:

场景如下: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>

上面中的

<!-- 加载配置文件 --> <context:property-placeholder location="classpath:db.properties"/>很奇怪,这里的db.properties明明在src/main/resources目录下。
为什么这里直接写classpath就可以了。

原因如下:
你仔细看config的图标。这个图标表示该目录是源文件夹。编译后源文件夹的非java文件会被copy到classes目录。 你可以右键 选择 build path ,然后可以把一些目录加入成为源文件夹,或者移出源文件夹。
无论有几个源文件夹,最后都会被加到classes目录里。



所以我们打开项目的classes目录:


就可以看到这么文件。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM