aspectj

AspectJ + Junit + Maven - pointcut recognized in tests but NoSuchMethodError: aspectOf() exception thrown

孤街醉人 提交于 2019-11-30 08:53:06
I have followed almost all JUnit + Maven + AspectJ questions here and even I am pretty sure I have everything set properly, I am unable to test it. I have a Maven module with just one aspect: @Aspect public class AssertionAspect { @Pointcut("execution(@org.junit.Test * *())") public void testMethodEntryPoint() {} @Before("testMethodEntryPoint()") public void executeBeforeEnteringTestMethod() { System.out.println("EXECUTE ACTION BEFORE ENTERING TEST METHOD"); } @After("testMethodEntryPoint()") public void executeAfterEnteringTestMethod() { System.out.println("EXECUTE ACTION AFTER ENTERING TEST

@AspectJ syntax for “after() : staticinitialization(*)”

佐手、 提交于 2019-11-30 08:52:28
问题 I'm trying to implement a tracing aspect using the pertypewithin instantiation model. In this way, I'll be able to use one logger per class per type. From some examples arround the we I can find this code to init the logger: public abstract aspect TraceAspect pertypewithin(com.something.*) { abstract pointcut traced(); after() : staticinitialization(*) { logger = Logger.getLogger(getWithinTypeName()); } before() : traced() { logger.log(...); } //.... } unfortunately, I'm not able to fully

Can we enable or disable Aspect based on value of any flag or through configuration file?

不想你离开。 提交于 2019-11-30 08:34:30
问题 I have added following dependency in pom.xml <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.8.5</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.8.5</version> </dependency> And enable AspectJ in appContext.xml as follows: And define aspect as

How do I pass arguments to Spring AOP advice with annotated parameters?

大城市里の小女人 提交于 2019-11-30 07:14:09
I am using Spring 3.1.2.RELEASE with cglib load-time weaving and I am trying to get advice to work with a method that has custom annotations and annotated parameters. Advice: @Aspect public class MyAdvice { @Around("execution(@com.mycompany.locking.Lock * *(@com.mycompany.locking.LockVal(*), ..)) " + "&& args(batch) && @args(propertyToLock)" public Object lockAndProceed(ProceedingJoinPoint pjp, Object batch, LockVal propertyToLock) throws Throwable { //Do stuff.... pjp.proceed(); } } Here is the class that I am testing: public interface UpdateManager { public void processUpdate(MyBatchObject

Spring Optimistic Locking:How to retry transactional method till commit is successful

て烟熏妆下的殇ゞ 提交于 2019-11-30 06:31:18
问题 I use Spring 2.5 and Hibernate JPA implementation with Java and "container" managed Transactions. I have a "after user commit" method that updates data in background and need to be committed regardless of ConcurrencyFailureException or StaleObjectStateException exception, because it will never be shown to client. In other words, need to make Optimistic Lock to Pessimistic. (Could happen if methods execution will take little bit longer and someone changed data in other transaction) I read a a

Mybatis多数据源读写分离(注解实现)

只谈情不闲聊 提交于 2019-11-30 06:24:57
Mybatis多数据源读写分离(注解实现) 首先需要建立两个库进行测试,我这里使用的是master_test和slave_test两个库,两张库都有一张同样的表(偷懒,喜喜),表结构 表名 t_user 字段名 类型 备注 id int 主键自增ID name varchar 名称 表中分别添加两条不同数据,方便测试 主数据库记录name为xiaobin,从库为xiaoliu 开始使用Springboot 整合mybatis,首先引入pom文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent<

Unit testing Spring @Around AOP methods

a 夏天 提交于 2019-11-30 06:20:49
问题 I can unit test most of my Spring classes without needing to do Spring "stuff". I can unit test @Before advice methods without using Spring too: Example code: @Before("execution(* run(..)) && " + "" + "target(target) && " + "args(name)") public void logName(Object target, String name) { logger.info("{} - run: {}", target, name); } Example test: @Test public void testLogName() { aspect.setLogger(mockLogger); aspect.logName(this,"Barry"); assertTrue(mockLogger.hasLogged("TestAspect - run: Barry

spring源码深度解析(1)--源码下载及环境搭建

不问归期 提交于 2019-11-30 05:48:36
源码下载 spring源码github仓库地址: https://github.com/spring-projects/spring-framework github访问慢和clone慢的解决方案: https://www.cnblogs.com/ericzz/p/10335600.html 源码导入eclipse 下载安装gradle环境 下载、安装、配置环境变量: 配置阿里云镜像地址: buildscript { repositories { maven{ url 'https://maven.aliyun.com/repository/google'} maven{ url 'https://maven.aliyun.com/repository/gradle-plugin'} maven{ url 'https://maven.aliyun.com/repository/public'} maven{ url 'https://maven.aliyun.com/repository/jcenter'} } } allprojects { repositories { maven{ url 'https://maven.aliyun.com/repository/google'} maven{ url 'https://maven.aliyun.com/repository

Why Spring AOP is not weaving external jars at runtime?

心已入冬 提交于 2019-11-30 05:20:25
I have a java application build upon Spring 3. This project has another jar as a dependency. This dependency contains a @org.aspectj.lang.annotation.Aspect class (lets say, com.aspectprovider.aspects.MyAspect ). There's a @Before advice to weave a method from classes that implements the interface Foo . Something like: @Before("execution(* com.project.Foo.save(..))") The Foo interface can be inside the "project" or in another jar. It doesn't matter for this example. My project contains classes that implements Foo . Those are the classes that I want it to be weaved, of course. My Spring

Spring中的AOP(二)——AOP基本概念和Spring对AOP的支持

泪湿孤枕 提交于 2019-11-30 05:05:16
AOP的基本概念 AOP从运行的角度考虑程序的流程,提取业务处理过程的切面。AOP面向的是程序运行中的各个步骤,希望以更好的方式来组合业务逻辑的各个步骤。AOP框架并不与特定的代码耦合,AOP框架能处理程序执行中特定切入点,而不与具体某个类耦合(即在不污染某个类的情况下,处理这个类相关的切点)。下面是一些AOP的一些术语: 切面(Aspect):业务流程运行的某个特定步骤,也就是应用运行过程的关注点,关注点通常会横切多个对象,因此常被称为横切关注点 连接点(JoinPoint):程序执行过程中明确的点,如方法调用,或者异常抛出。Spring AOP中,连接点总是方法调用。 增强处理(Advice):AOP框架在特定的切入点执行的增强处理。处理有around,before,after等类型。(说明:AOP是比较前沿的知识,而大部分国内翻译人士在翻译计算机文献时,总是一边看各种翻译软件和词典,一边逐字逐句的翻译,而不是先去从总体上把握知识的架构。因此难免导致一些术语翻译的词不达意,在AOP的术语上也存在较大差异,对于Advice一词,有人翻译为“通知”,有人翻译为“建议”......实际上,Advice是指AOP框架在特定切面所加入的某种处理,笔者这里翻译为“增强处理”,希望可以表达出Advice的真正含义) 切入点(PointCut):可以插入增强处理的连接点。简而言之