当前位置: 首页 > news >正文

湖北省建设厅网站长沙网站推广工具

湖北省建设厅网站,长沙网站推广工具,南通网站搭建定制,建设银行网站登录密码目录 半注解形式: 业务层接口实现类: 编写切面类: 在配置文件里面唯一需要加的: 测试类: 全注解形式: 不要配置文件,改为配置类: 同样的业务层接口实现类: 同样的…

目录

半注解形式:

业务层接口+实现类:

编写切面类:

在配置文件里面唯一需要加的:

测试类:

全注解形式:

不要配置文件,改为配置类:

同样的业务层接口+实现类:

同样的自定义切面类:

测试类改为不加载配置文件加载配置类:


半注解形式:

业务层接口+实现类:

public interface UserService {public void save();
}@Service
public class UserServiceImpl implements UserService {//保存方法
//    @Overridepublic void save() {System.out.println("业务层方法执行了!!!");//int i=5/0;}
}

编写切面类:

/*** @Component  // 把该类交给IOC去管理* @Aspect     // 声明是切面类  == <aop:aspect ref="myXmlAspect">*/
@Component
@Aspect
public class MyAnnoAspect {/*** 通知的方法*/// @Before(value = "切入点的表达式")@Before("execution(public void com.qcby.demo1.UserServiceImpl.save())")public void log(){System.out.println("前置方法执行了!!");}
}

在配置文件里面唯一需要加的:

1、开启注解扫描:

2、开启aop自动代理:

<?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:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd"><!--开启注解扫描 扫描所有被spring管理的类--><context:component-scan base-package="com.qcby"/><!--开启AOP注解支持--><aop:aspectj-autoproxy/>
</beans>

测试类:

/*** 测试类* 测试AOP的增强* @RunWith(SpringJUnit4ClassRunner.class)  声明为测试单元* @ContextConfiguration("classpath:applicationContext.xml")  加载配置文件*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class TestDemo1 {@Autowiredprivate UserService userService;@Testpublic void run(){userService.save();}
}

运行结果:

全注解形式:

不要配置文件,改为配置类:

@Configuration // 配置类
@ComponentScan(value = "com.qcby") // 扫描包
@EnableAspectJAutoProxy // 开启自动代理 == <aop:aspectj-autoproxy />
public class SpringConfig {
}

同样的业务层接口+实现类:

public interface UserService {public void save();
}@Service
public class UserServiceImpl implements UserService {//保存方法
//    @Overridepublic void save() {System.out.println("业务层方法执行了!!!");//int i=5/0;}
}

同样的自定义切面类:

/*** @Component  // 把该类交给IOC去管理* @Aspect     // 声明是切面类  == <aop:aspect ref="myXmlAspect">*/
@Component
@Aspect
public class MyAnnoAspect {/*** 通知的方法*/// @Before(value = "切入点的表达式")@Before("execution(public void com.qcby.demo1.UserServiceImpl.save())")public void log(){System.out.println("前置方法执行了!!");}
}

测试类改为不加载配置文件加载配置类:

/*** 测试类* 测试AOP的增强* @RunWith(SpringJUnit4ClassRunner.class)  声明为测试单元* @ContextConfiguration("classpath:applicationContext.xml")  加载配置文件*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class TestDemo1 {@Autowiredprivate UserService userService;@Testpublic void run(){userService.save();}
}

运行结果:

http://www.hkea.cn/news/623562/

相关文章:

  • c做的网站淄博做网站的公司
  • 网站开发制作公司郑州网站建设外包
  • 注册域名用个人还是公司好长沙seo优化排名
  • 电子商务网站建设与维护展望今日新闻联播
  • 网站建设主流技术站长之家ping检测
  • 温州建设集团有限公司网站首页百度手机版网页
  • 广西网络干部学院官网seo推广人员
  • 可以做红娘的相亲网站江北seo综合优化外包
  • 公司建设网站需要注意什么软文广告示范
  • 高端网站建设 引擎技企业网页
  • 模仿别人网站百度外链查询工具
  • 教程建设网站广告免费发布信息平台
  • wordpress php5.4支持宁波seo排名优化
  • 宁波制作网站哪个好百度怎么发自己的小广告
  • 新浪网站用什么语言做的百度软件下载
  • wordpress如何做网站重庆seo俱乐部联系方式
  • 教育局两学一做网站深圳全网推广平台
  • 淘宝做详情页代码网站免费大数据查询平台
  • 苹果做安卓游戏下载网站好新媒体营销案例ppt
  • 网络营销实务关键词优化seo优化排名
  • 网站推广优化教程游戏代理加盟平台
  • 网站提升权重全国疫情高峰感染进度
  • 营销型网站怎么做智能建站abc
  • 捷信做单官方网站网络服务主要包括什么
  • 网站建设的方案费用什么时候网络推广
  • 这么做3d展示网站公司百度官网优化
  • 工业设计软件上市公司搜索引擎优化的方法
  • 网站建设公司创意网站网络推广推广
  • 浙江三建建设集团有限公司网站关键词的作用
  • 网站建设官方网站教育培训机构加盟十大排名