- 浏览: 159374 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (212)
- Java基础 (67)
- Js基础 (14)
- NoSQL (7)
- Spring (34)
- sql (8)
- JMS (1)
- Redis (8)
- Flex (5)
- java线程 (2)
- Linux (8)
- Hibernate (3)
- maven (12)
- bug (1)
- node.js (3)
- servlet (7)
- 设计模式 (6)
- struts (1)
- bootstrap3.js (2)
- cxf (1)
- Thymeleaf (2)
- HTML (1)
- parsley.js (1)
- jquery (1)
- restful (4)
- eclipse&Idea (3)
- Spring boot (2)
- Http (1)
- DB (3)
- Jboss (1)
- web (1)
- rpc (3)
- zookeeper (1)
- 杂谈 (4)
- angularjs (2)
- selenium2.0 (1)
- Mybatis (6)
- MySql (7)
- 数据结构 (1)
- Nginx (2)
最新评论
-
wangyudong:
由Spring Boot实现的微服务需要有比较好的工具去测试R ...
spring boot 启动 -
arsemilan:
很实用的sql,面试必备
sql 简单应用
package com.spring.aop.service;
public interface UserService {
void save(String name);
void save();
}
package com.spring.aop.service.impl;
import org.springframework.stereotype.Service;
import com.spring.aop.service.UserService;
@Service
public class UserServiceBean implements UserService {
@Override
public void save(String name) {
System.out.println("UserService 正在保存"+name);
}
@Override
public void save() {
System.out.println("UserService 正在保存。。。空参数");
}
}
package com.spring.aop.interceptor;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Aspect
public class MyInterceptor {
@Pointcut("execution(* com.spring.aop.service..*(..)) ")
private void anyMethod(){};
@Before("anyMethod()")
public void beforeLog(){
System.out.println("method do before log...");
}
@After("anyMethod()")
public void afterLog(){
System.out.println("method do after log...");
}
//方法执行的前后调用
@Around("anyMethod()")
public Object around(ProceedingJoinPoint point) throws Throwable{
System.out.println("begin around");
Object object = point.proceed();
System.out.println("end around");
return object;
}
}
package com.spring.aop.test;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.spring.aop.interceptor.MyInterceptor;
import com.spring.aop.service.UserService;
public class InterceptorTest {
@Autowired
private UserService userService;
@Test
public void test() {
fail("Not yet implemented");
}
@Test
public void interceptorTest(){
ApplicationContext cxt = new ClassPathXmlApplicationContext("beans.xml");
UserService service = (UserService)cxt.getBean("userService");
userService.save();
}
}
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<aop:aspectj-autoproxy/>
<bean id="myInterceptor" class="com.spring.aop.interceptor.MyInterceptor"></bean>
<bean id="userService" class="com.spring.aop.service.impl.UserServiceBean"></bean>
</beans>
public interface UserService {
void save(String name);
void save();
}
package com.spring.aop.service.impl;
import org.springframework.stereotype.Service;
import com.spring.aop.service.UserService;
@Service
public class UserServiceBean implements UserService {
@Override
public void save(String name) {
System.out.println("UserService 正在保存"+name);
}
@Override
public void save() {
System.out.println("UserService 正在保存。。。空参数");
}
}
package com.spring.aop.interceptor;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Aspect
public class MyInterceptor {
@Pointcut("execution(* com.spring.aop.service..*(..)) ")
private void anyMethod(){};
@Before("anyMethod()")
public void beforeLog(){
System.out.println("method do before log...");
}
@After("anyMethod()")
public void afterLog(){
System.out.println("method do after log...");
}
//方法执行的前后调用
@Around("anyMethod()")
public Object around(ProceedingJoinPoint point) throws Throwable{
System.out.println("begin around");
Object object = point.proceed();
System.out.println("end around");
return object;
}
}
package com.spring.aop.test;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.spring.aop.interceptor.MyInterceptor;
import com.spring.aop.service.UserService;
public class InterceptorTest {
@Autowired
private UserService userService;
@Test
public void test() {
fail("Not yet implemented");
}
@Test
public void interceptorTest(){
ApplicationContext cxt = new ClassPathXmlApplicationContext("beans.xml");
UserService service = (UserService)cxt.getBean("userService");
userService.save();
}
}
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<aop:aspectj-autoproxy/>
<bean id="myInterceptor" class="com.spring.aop.interceptor.MyInterceptor"></bean>
<bean id="userService" class="com.spring.aop.service.impl.UserServiceBean"></bean>
</beans>
发表评论
-
spring+quartz
2015-08-17 17:51 6771.pom.xml <dependency> ... -
[转]org.springframework.web.util.IntrospectorCleanupListener作用
2015-07-14 18:11 947spring中提供了一个名为org.springframew ... -
spring redis
2015-06-13 16:43 83911.pom.xml <!-- spring-d ... -
Spring Transaction 分析事务属性
2015-05-12 17:15 407众所周知的ACID属性: 原子性(atomicity)、一 ... -
BCryptPasswordEncoder
2015-04-15 17:17 3532import org.springframework.se ... -
spring Integration
2015-03-25 11:09 1515<beans xmlns="http://w ... -
Spring DateFormatter &&CurrencyFormatter
2015-03-09 17:57 4701.DateFormatter java.util ... -
spring Interceptor小应用
2015-02-11 15:54 336性能监控 如记录一下请求的处理时间,得到一些慢请求(如处理 ... -
Spring3中的mvc:interceptors标签配置拦截器/spring boot HandlerInterceptor
2015-02-11 14:47 785<?xml version="1.0&quo ... -
Spring Annotation (3)
2015-02-09 19:50 5091.类内部的注解,如:@Autowire、@Value、@R ... -
Spring Annotation (2)
2015-02-09 19:47 4441.从Spring2.0以后的版本中,Spring也引入了基 ... -
Spring Annotation (1)
2015-02-09 19:45 3301.使用 @Repository、@Service、@Con ... -
Java的注解机制——Spring自动装配的实现原理
2015-02-05 19:51 429jDK1.5加入了对注解机 ... -
saveAndFlush and save
2015-01-23 18:56 1083On saveAndFlush, changes will ... -
SpringMVC中JSP取不到ModelAndView的数据原因
2015-01-23 10:17 844在项目中发现用JSP取不到ModelAndView的数据, ... -
spring 小知识
2015-01-21 15:06 2981.处理器映射DefaultAnnotationHa ... -
Spring MVC 流程图
2015-01-20 16:03 721Spring工作流程描述 1. ... -
Spring Scope
2014-12-08 10:42 264详细参考:http://blog.csd ... -
Jpa-JpaRepository
2014-12-04 16:06 5331.查询自定义的dto @Query(nativeQu ... -
spring web put与delete方法的调用
2014-11-24 15:01 1301在form中,method只用GET/POST。如果 ...
相关推荐
SpringBoot AOP各种注解、自定义注解、鉴权使用案例SpringBoot AOP各种注解、自定义注解、鉴权使用案例SpringBoot AOP各种注解、自定义注解、鉴权使用案例
java aop、ioc 、注解 实例 Demo
基于Spring boot + maven,以注解+AOP方式实现的java后端项目接口参数校验框架。迄今为止使用最简单、最容易理解的参数校验方案。博客地址:https://blog.csdn.net/weixin_42686388/article/details/104009771
3、对spring aop认识模糊的,不清楚如何实现Java 自定义注解的 4、想看spring aop 注解实现记录系统日志并入库等 二、能学到什么 1、收获可用源码 2、能够清楚的知道如何用spring aop实现自定义注解以及注解的逻辑...
关于AOP注解前置通知、后置通知、返回通知、异常通知的注解注释及应用
spring AOP,注解方式的实现! 内部方法的拦截
基于注解实现SpringAop基于注解实现SpringAop基于注解实现SpringAop
java springAOP 事务+注释 带全部jar包! 即下即用!
Spring主要有两大思想,一个是IoC,另一个就是AOP,对于IoC,AOP的原理就是java的动态代理机制
spring中aop的注解的使用开发,包括bean注解.rar
spring-aop:AOP核心功能,例如代理工厂等等aspectjweaver:简单理解,支持切入点表达式等等aspectjrt:简单理解,支持aop相关注解等等
注解方式实现AOP编程
Android AOP注解Annotation详解(一) Android AOP之注解处理解释器详解(二) Android AOP 注解详解及简单使用实例(三) Android AOP 等在Android上应用越来越广泛,例如框架ButterKnife,Dagger2,EventBus3等等...
spring aop 采用注解定义以及xml定义,在java四层结构中无缝实现
Spring通过注解实现AOP,Spring通过注解实现AOP,Spring通过注解实现AOPSpring通过注解实现AOP,Spring通过注解实现AOP,Spring通过注解实现AOP
spring5aop注解需要jar
Spring的AOP开发(XML)Spring的AOP的注解开发 代码案例
以注解方式模拟Spring IoC AOP,了解Spring是如何实现的.
java手动实现、注解方式实现两种方法实现springaop编程,包含源码+jar包+解释
springboot spring aop 拦截器 注解方式实现脱敏(涉及到:pom.xml -->application.properties --->启动类-->拦截器)