b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

struts实现原理 maven(二) maven项目构建ssh工程(父工程与子模(3)

电脑杂谈  发布时间:2018-01-15 20:03:33  来源:网络整理

其他几个Student.java这些就不用看了,太简单了。

StudentTest.java这个需要讲解一下,因为这里使用junit测试的时候,会报错,报的错误是找不到junit的jar包,这里我们就会很疑惑,为什么会找不到该jar包呢,不是在父工程里面都导入了junit的jar包了吗?这里出错的原因是传递依赖的范围问题。

将父工程看做A项目(下面简称A),将该子模块ssh_dao看做B项目(下面简称B),A依赖junit的jar包是直接依赖。B继承A(实际操作就是B中填写A的坐标)也可以看成一种依赖,那么就是这样一种关系,B 依赖 A 依赖 junit, A依赖junit是直接依赖没错,那么B跟junit的关系就叫做传递(间接)依赖,我们知道A依赖的junit时,junit的jar包可以设置在A中的使用范围,就是scope属性,可以为compile,test等,而junit设置的是test,只在A中测试的时候用,那么B想用junit时,junit的作用范围是不是也是test呢?这就有一种关系。具体看表。

按照刚才上面的例子,来看看在B中,junit的作用范围是什么?首先看B 依赖 A,直接依赖,并且A在B中的作用范围是compile(没设置就默认),所以在直接依赖这一列中找到compile这一行,也就是用红色框框框起来的一行,然后B 依赖 junit,对A来说,A 是传递依赖 junit,这时候看junit设置的作用范围是多少(也就是看junit在B中的使用范围是什么)?看传递依赖这一行,junit设置的是test,找到test这一列,看相交的地方,是空的,则说明,junti在B中的test范围不能够使用,其实看图,B中任何范围内都不能够使用junit,这样你就理解了这张图是什么意思。这只是原理,实际上我们解决这种问题的时候,用一个简单粗暴的解决方案。什么jar包丢失了,我们就再次导入一次jar包即可。

所以在ssh_dao子模块的pom.xml中有junit的坐标才能使用test

2.3、创建ssh_service子模块

方法同ssh_dao模块创建方法一样,模块名称为ssh_service。

mybatis原理_struts实现原理_struts2 springmvc

看ssh_service和ssh_parent的pom.xml文件,会出现和ssh_dao创建时一样的情况,ssh_service多出一个parents结点,ssh_parent多个一个module结点

在ssh_service的pom.xml中添加两个依赖

然后编写service层的代码,

主要关注一下applicationContext-service.xml中的事务的相关代码

<?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:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
                              http://www.springframework.org/schema/beans/spring-beans.xsd
                              http://www.springframework.org/schema/tx 
                              http://www.springframework.org/schema/tx/spring-tx.xsd
                              http://www.springframework.org/schema/aop 
                              http://www.springframework.org/schema/aop/spring-aop.xsd
                              http://www.springframework.org/schema/context 
                              http://www.springframework.org/schema/context/spring-context.xsd">
        <!-- 事务管理器 -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <!--  事务通知 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="save*" propagation="REQUIRED"/>
            <tx:method name="insert*" propagation="REQUIRED"/>
            <tx:method name="update*" propagation="REQUIRED"/>
            <tx:method name="delete*" propagation="REQUIRED"/>
            
            <tx:method name="get*" read-only="true"/>
            <tx:method name="*" propagation="REQUIRED"/>
        </tx:attributes>
    </tx:advice>
    <!-- aop -->
    <aop:config>
        <aop:pointcut id="pointcut" expression="execution(* cn.wuhao.ssh_service.service.impl.*.*(..))" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut" />
    </aop:config>

         <!-- 在StudentService中注入StudentDao -->
         <bean id="studentService" class="com.wuhao.ssh_service.service.impl.StudentServiceImpl">
             <property name="studentDao" ref="studentDao"></property>
         </bean>                   
                              
</beans>


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-60366-3.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 王光庭
      王光庭

      用户名输入时候键盘居然弹不出

    • 韩定辞
      韩定辞

      发财的标准是多少

      • 冯红芳
        冯红芳

        期待演员杨洋给我们展现他的潜力和作品

    热点图片
    拼命载入中...