企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
**1.UserService** ~~~ package com.nobb.service; public interface UserService { void save(); void delete(); void update(); void find(); } ~~~ **2.UserServiceImpl** ~~~ package com.nobb.service; public class UserServiceImpl implements UserService { @Override public void save() { System.out.println("save()"); } @Override public void delete() { System.out.println("delete()"); } @Override public void update() { System.out.println("update()"); } @Override public void find() { System.out.println("find()"); } } ~~~ **3.MyAdvice** ~~~ package com.nobb.advice; /** * 通知 */ public class MyAdvice { public void before(){ System.out.println("前置通知"); } public void after(){ System.out.println("后置通知"); } public void afterThrowing(){ System.out.println("异常通知"); } public void end(){ System.out.println("最终通知"); } } ~~~ **4.测试代码** ~~~ import com.nobb.service.UserService; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.annotation.Resource; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:applicationContext.xml") public class App { //byName @Resource(name="userService") private UserService userService; @Test public void fun1(){ userService.save(); } } ~~~ **5.测试结果** 前置通知 save() 后置通知 最终通知