aop

How to write an aspect or annotation for a method that cannot update any instance variables?

て烟熏妆下的殇ゞ 提交于 2020-01-16 19:01:37
问题 How to write an aspect or annotation for a method that cannot update any instance variables? Say for example I have the following java class public class Foo { String name; int id; public getName() { return name; } } Now say I want to write an aspect or in general, some annotation call it say @readOnly which can enforce getName() method to not modify either name or id so if do public class Foo { String name; int id; @readOnly public getName() { name = "hello world"; id = 7564; return name; }

How to write an aspect or annotation for a method that cannot update any instance variables?

半城伤御伤魂 提交于 2020-01-16 19:00:10
问题 How to write an aspect or annotation for a method that cannot update any instance variables? Say for example I have the following java class public class Foo { String name; int id; public getName() { return name; } } Now say I want to write an aspect or in general, some annotation call it say @readOnly which can enforce getName() method to not modify either name or id so if do public class Foo { String name; int id; @readOnly public getName() { name = "hello world"; id = 7564; return name; }

springMVC + Spring + MyBatis 整合

一曲冷凌霜 提交于 2020-01-16 17:54:31
整理下SSM(基于注解)的整合 1. web.xml 配置文件 1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 5 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 6 7 <!-- log4j 配置 --> 8 <context-param> 9 <param-name>log4jConfigLocation</param-name> 10 <param-value>classpath:log4j.properties</param-value> 11 </context-param> 12 <context-param> 13 <param-name>log4jRefreshInterval</param-name> 14 <param-value>60</param-value> 15 </context-param> 16 <listener>

Help with pointcut - AspectJ

假如想象 提交于 2020-01-16 14:03:19
问题 I'm just a bit confused with the parameters in a pointcut would appreciate if anyone could explain it to me... import Java.util.logging.*; import org.aspect j.lang.*; public aspect TraceAspect { private Logger _logger = Logger.getLogger("trace"); TraceAspectV2() { _logger.setLevel(Level.ALL); } pointcut traceMethods() (execution(* Account.*(..)) || execution(*.new(..))) && !within(TraceAspect); before () : traceMethods() { if (_logger.isLoggable(Level.INFO)) { Signature sig =

Capture setters inside mapper method using AspectJ in Spring

不打扰是莪最后的温柔 提交于 2020-01-16 08:58:35
问题 I have java classes like this : @Data public class Lead { private A a; ... } @Data public class A { private B b; private String c; private List<Integer> d; } @Data public class B { private String e; private String f; } I have a mapper method with annotation like this : @FieldPermissionAnnotation("a") public A fetchA(//Some DB Entities) { A a = new A(); ... a.setB(fetchB()); ... a.setC(fetchC()); ... a.setD(fetchD()); } My FieldPermissionAspect fetches the permission-field mapping from db for

AOP: Able to Intercept JDBCTemplate calls but not NamedParameterJdbcTemplate calls

 ̄綄美尐妖づ 提交于 2020-01-16 08:46:19
问题 I have made two test methods. One uses JdbcTemplate to make the query while other uses NamedParameterJDBCTemplate. Using NamedParameterJdbcTemplate: @Autowired JdbcTemplate jdbcTemplate; public Student findById(long id) { NamedParameterJdbcTemplate apptemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource()); return apptemplate.queryForObject("select * from student where id="+id, Collections.emptyMap(), new BeanPropertyRowMapper< Student >(Student.class)); } Using JdbcTemplate

AOP: Able to Intercept JDBCTemplate calls but not NamedParameterJdbcTemplate calls

人盡茶涼 提交于 2020-01-16 08:46:11
问题 I have made two test methods. One uses JdbcTemplate to make the query while other uses NamedParameterJDBCTemplate. Using NamedParameterJdbcTemplate: @Autowired JdbcTemplate jdbcTemplate; public Student findById(long id) { NamedParameterJdbcTemplate apptemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource()); return apptemplate.queryForObject("select * from student where id="+id, Collections.emptyMap(), new BeanPropertyRowMapper< Student >(Student.class)); } Using JdbcTemplate

【spring】AOP学习笔记

倾然丶 夕夏残阳落幕 提交于 2020-01-16 02:51:57
【spring】AOP学习笔记 一、前言 1. 举个栗子 2. 事务控制 二、动态代理 1. JDK代理 2. CGLIB代理 三、重点来了 1. 概念 2. 相关术语 3. 依赖 4. 基于XML的AOP配置步骤 5. 切入点表达式的写法 6. 五种通知类型 一、前言 1. 举个栗子 转账案例: 2. 事务控制 二、动态代理 不修改源码的基础上对方法增强 Spring正式引入代理的特点:如果是对接口代理使用JDK代理;如果对类代理使用Cglib代理。 1. JDK代理 目标对象面向接口,被代理类最少实现一个接口,如果没有则不能使用(spring默认的代理方式是JDK代理) 使用Proxy类中的newProxyInstance方法,newProxyInstance方法的参数: ClassLoader:类加载器 用于加载代理对象字节码。和被代理对象使用相同的类加载器。固定写法。 Class[]:字节码数组 用于让代理对象和被代理对象有相同方法。固定写法。 InvocationHandler:用于提供增强的代码 写代理细节。一般都是写一个该接口的实现类,通常情况下都是匿名内部类,但不是必须的。 public class Client { public static void main(String[] args) { final Producer producer = new

AttributeTargetElements = MulticastTargets.Method isn't respected?

雨燕双飞 提交于 2020-01-16 01:19:29
问题 I applied this aspect: [Serializable] [MulticastAttributeUsage(MulticastTargets.Method)] // regular methods, excluding ctors! public class WmiClassMethodAspect : OnMethodBoundaryAspect { public WmiClassMethodAspect() { ApplyToStateMachine = false; } // PostSharp Express edition... public override void OnEntry(MethodExecutionArgs args) { //base.OnEntry(args); } public override void OnExit(MethodExecutionArgs args) { //base.OnExit(args); } } over certain namespace 's class: [assembly:

[原]Spring AOP 详解

亡梦爱人 提交于 2020-01-15 23:59:12
原理 AOP(Aspect Oriented Programming),也就是面向方面编程的技术。AOP基于IoC基础,是对OOP的有益补充。   AOP将应用系统分为两部分,核心业务逻辑(Core business concerns)及横向的通用逻辑,也就是所谓的方面Crosscutting enterprise concerns,例如,所有大中型应用都要涉及到的持久化管理(Persistent)、事务管理(Transaction Management)、安全管理(Security)、日志管理(Logging)和调试管理(Debugging)等。   AOP正在成为软件开发的下一个光环。使用AOP,你可以将处理aspect的代码注入主程序,通常主程序的主要目的并不在于处理这些aspect。AOP可以防止代码混乱。   Spring framework是很有前途的AOP技术。作为一种非侵略性的、轻型的AOP framework,你无需使用预编译器或其他的元标签,便可以在Java程序中使用它。这意味着开发团队里只需一人要对付AOP framework,其他人还是像往常一样编程。    AOP概念   让我们从定义一些重要的AOP概念开始。   — 方面(Aspect):一个关注点的模块化,这个关注点实现可能另外横切多个对象。事务管理是J2EE应用中一个很好的横切关注点例子