Spring注釈配置、Spring aop、Junit統合——Spring学習day 2

6818 ワード

コメントの設定:
1.主な構成ファイルに新しい名前空間(制約)を導入する
preferenceにファイルを導入する
2.注釈プロキシを使用したプロファイルのオープン
"1.0" encoding="UTF-8"?>
"http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd ">
base-package="com.littlepage.entity">
3.類表の名前の注釈
//xmlファイルに相当します.beanを配合したnameはuserです.
@Component("user")/entity層@Service("user")//service層@Controller("user")//web層@Repository("user")//dao層
四つの注釈は同じですが、注釈の名前によって機能が分かります.
@Scope(「singlenton」)
scope機能は前のブログで話しました.
@Autowared
クラスを自動的に見つけます.
4.運転
stsプラグイン:
1.手動設置(成功率が低い)
2.先生のEclipseを使っています.
3.springプラグインを装着したeclipse
SpringのAOP:
AOP名詞解釈:
ジョインポイント(接続点):ターゲットオブジェクトにおいて、強化できるすべての方法.(未代理の方法)
Pointcut(切り込みポイント):対象オブジェクトにおいて、強化された方法.(代理された方法)
Advice(通知/強化):強化コード
ターゲット:プロキシ対象
Weaving(編入):切込点に通知を適用する過程
Proxy(代理):対象に織り込まれた後に形成される代理対象を通知します.
Asppect(うどん):切り込みポイント+お知らせ
AOP:aspect orented programming
 
ステップ:
1.準備作業、aop(制約)名前空間を導入する
"http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd ">
2.ターゲットの設定
package com.littlepage.entity;

import org.aspectj.lang.ProceedingJoinPoint;

/**
 *    
 * @author 74302
 *
 */
public class MyAdvice {
    //    ->          
    public void before(){
        System.out.println("      ");
    }
    //    (      ,    )->          
    public void afterReturning(){
        System.out.println("      ");
    }
    //    ->           
    public Object around(ProceedingJoinPoint pjp) throws Throwable{
        System.out.println("");
        Object proceed=pjp.proceed();//      
        System.out.println("           ");
        return proceed;
    }
    //      ->    ,    
    public void afterException(){
        System.out.println("");
    }
    //    (        ,    )
    public void after(){
        System.out.println("");
    }
    
    
}
3.目標をオブジェクトに織り込む
4.設定は、ターゲットに織り込むことを通知します.
 
転載先:https://www.cnblogs.com/littlepage/p/10858680.html