通過自定義spring註解方式,給指定的service業務類新增註解,用於日誌記錄等操作。
*自定義註解 攔截controller
*/
@target()
@retention(retentionpolicy.runtime)
@documented
public @inte***ce systemcontrollerlog
@before("systemloghelper()")
public void before(joinpoint point) throws classnotfoundexception
private void getcontrollermethoddescription(joinpoint point) throws classnotfoundexception }}
}}3、測試service類
import org.springframework.stereotype.component;
@component
public class annotationservice
@systemcontrollerlog(logaction = "testdemo.class", logcontent = "測試註解切面", moduleid = 159)
public void test2(string name,string password)
}4、測試類
import org.junit.test;
import org.junit.runner.runwith;
import org.springframework.beans.factory.annotation.autowired;
import org.springframework.test.context.contextconfiguration;
import org.springframework.test.context.junit4.springjunit4classrunner;
@runwith(value = springjunit4classrunner.class)
@contextconfiguration(locations = )
public class systemlogservicehelpertest
}5、xml配置檔案
<?xml version="1.0" encoding="utf-8"?>
xmlns:xsi="" xmlns:p=""
xmlns:tx="" xmlns:mvc=""
xmlns:aop="" xmlns:context=""
xmlns:jee=""
xsi:schemalocation=" /spring-aop-4.0.xsd
/spring-mvc-4.0.xsd
/spring-beans-4.0.xsd
/spring-context-4.0.xsd
/spring-tx-4.0.xsd
/spring-jee.xsd">
註解方式建立切面
使用註解來建立切面是 aspectj 5 引入的關鍵特性。aspectj 面向註解模型可以非常簡單的通過少量註解把任意類轉換為切面。這種新特性通常稱為 aspectj。package com.aspect import org.aspectj.lang.annotation.aspect impor...
Spring實戰4 4 註解切面
目錄 aspect cannot be resolved to a type 註解切面方式實現aop程式設計 1 先引入aop相關的jar檔案 2 配置spring idol.xml中引入aop命名空間 3 配置spring idol.xml中開啟aop註解掃瞄,如下配置所示 開發步驟 技巧 找到檔...
springAOP註解式切面實現
org.springframework spring aop 4.3.11.release org.springframework spring aspects 4.3.11.release 我這裡監聽的是service層 component aspect public class testaspe...