Merge branch '6.0.x'
# Conflicts: # spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java # spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionInterceptorTests.java
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,9 +19,9 @@ package org.springframework.aop.aspectj;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import test.mixin.Lockable;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.aop.testfixture.mixin.Lockable;
|
||||
import org.springframework.beans.testfixture.beans.ITestBean;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
|
||||
@@ -46,23 +46,25 @@ import org.springframework.aop.framework.ProxyConfig;
|
||||
import org.springframework.aop.support.AbstractPointcutAdvisor;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
|
||||
import org.springframework.aop.testfixture.aspectj.PerTargetAspect;
|
||||
import org.springframework.beans.PropertyValue;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.config.MethodInvokingFactoryBean;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.testfixture.beans.ITestBean;
|
||||
import org.springframework.beans.testfixture.beans.TestBean;
|
||||
import org.springframework.cglib.proxy.Factory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.core.DecoratingProxy;
|
||||
import org.springframework.core.NestedRuntimeException;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@@ -208,6 +210,31 @@ class AspectJAutoProxyCreatorTests {
|
||||
assertThat(adrian1.getAge()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test // gh-31238
|
||||
void cglibProxyClassIsCachedAcrossApplicationContextsForPerTargetAspect() {
|
||||
Class<?> configClass = PerTargetProxyTargetClassTrueConfig.class;
|
||||
TestBean testBean1;
|
||||
TestBean testBean2;
|
||||
|
||||
// Round #1
|
||||
try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(configClass)) {
|
||||
testBean1 = context.getBean(TestBean.class);
|
||||
assertThat(AopUtils.isCglibProxy(testBean1)).as("CGLIB proxy").isTrue();
|
||||
assertThat(testBean1.getClass().getInterfaces())
|
||||
.containsExactlyInAnyOrder(Factory.class, SpringProxy.class, Advised.class);
|
||||
}
|
||||
|
||||
// Round #2
|
||||
try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(configClass)) {
|
||||
testBean2 = context.getBean(TestBean.class);
|
||||
assertThat(AopUtils.isCglibProxy(testBean2)).as("CGLIB proxy").isTrue();
|
||||
assertThat(testBean2.getClass().getInterfaces())
|
||||
.containsExactlyInAnyOrder(Factory.class, SpringProxy.class, Advised.class);
|
||||
}
|
||||
|
||||
assertThat(testBean1.getClass()).isSameAs(testBean2.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
void twoAdviceAspect() {
|
||||
ClassPathXmlApplicationContext bf = newContext("twoAdviceAspect.xml");
|
||||
@@ -354,33 +381,6 @@ class AspectJAutoProxyCreatorTests {
|
||||
|
||||
}
|
||||
|
||||
@Aspect("pertarget(execution(* *.getSpouse()))")
|
||||
class PerTargetAspect implements Ordered {
|
||||
|
||||
public int count;
|
||||
|
||||
private int order = Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
@Around("execution(int *.getAge())")
|
||||
public int returnCountAsAge() {
|
||||
return count++;
|
||||
}
|
||||
|
||||
@Before("execution(void *.set*(int))")
|
||||
public void countSetter() {
|
||||
++count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
}
|
||||
|
||||
@Aspect
|
||||
class AdviceUsingThisJoinPoint {
|
||||
|
||||
@@ -642,6 +642,23 @@ class ProxyTargetClassFalseConfig extends AbstractProxyTargetClassConfig {
|
||||
class ProxyTargetClassTrueConfig extends AbstractProxyTargetClassConfig {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAspectJAutoProxy(proxyTargetClass = true)
|
||||
class PerTargetProxyTargetClassTrueConfig {
|
||||
|
||||
@Bean
|
||||
@Scope("prototype")
|
||||
TestBean testBean() {
|
||||
return new TestBean("Jane", 34);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Scope("prototype")
|
||||
PerTargetAspect perTargetAspect() {
|
||||
return new PerTargetAspect();
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface MessageGenerator {
|
||||
String generateMessage();
|
||||
|
||||
@@ -34,10 +34,6 @@ import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import test.mixin.LockMixin;
|
||||
import test.mixin.LockMixinAdvisor;
|
||||
import test.mixin.Lockable;
|
||||
import test.mixin.LockedException;
|
||||
|
||||
import org.springframework.aop.Advisor;
|
||||
import org.springframework.aop.AfterReturningAdvice;
|
||||
@@ -64,6 +60,10 @@ import org.springframework.aop.testfixture.advice.MyThrowsHandler;
|
||||
import org.springframework.aop.testfixture.interceptor.NopInterceptor;
|
||||
import org.springframework.aop.testfixture.interceptor.SerializableNopInterceptor;
|
||||
import org.springframework.aop.testfixture.interceptor.TimestampIntroductionInterceptor;
|
||||
import org.springframework.aop.testfixture.mixin.LockMixin;
|
||||
import org.springframework.aop.testfixture.mixin.LockMixinAdvisor;
|
||||
import org.springframework.aop.testfixture.mixin.Lockable;
|
||||
import org.springframework.aop.testfixture.mixin.LockedException;
|
||||
import org.springframework.beans.testfixture.beans.IOther;
|
||||
import org.springframework.beans.testfixture.beans.ITestBean;
|
||||
import org.springframework.beans.testfixture.beans.Person;
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.io.Serializable;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import test.mixin.LockMixinAdvisor;
|
||||
|
||||
import org.springframework.aop.ClassFilter;
|
||||
import org.springframework.aop.MethodMatcher;
|
||||
@@ -31,6 +30,7 @@ import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
|
||||
import org.springframework.aop.testfixture.advice.CountingBeforeAdvice;
|
||||
import org.springframework.aop.testfixture.interceptor.NopInterceptor;
|
||||
import org.springframework.aop.testfixture.mixin.LockMixinAdvisor;
|
||||
import org.springframework.beans.testfixture.beans.ITestBean;
|
||||
import org.springframework.beans.testfixture.beans.TestBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
@@ -27,8 +27,6 @@ import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import test.mixin.Lockable;
|
||||
import test.mixin.LockedException;
|
||||
|
||||
import org.springframework.aop.ClassFilter;
|
||||
import org.springframework.aop.IntroductionAdvisor;
|
||||
@@ -42,6 +40,8 @@ import org.springframework.aop.testfixture.advice.CountingBeforeAdvice;
|
||||
import org.springframework.aop.testfixture.advice.MyThrowsHandler;
|
||||
import org.springframework.aop.testfixture.interceptor.NopInterceptor;
|
||||
import org.springframework.aop.testfixture.interceptor.TimestampIntroductionInterceptor;
|
||||
import org.springframework.aop.testfixture.mixin.Lockable;
|
||||
import org.springframework.aop.testfixture.mixin.LockedException;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.aop.framework.autoproxy;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import test.mixin.Lockable;
|
||||
|
||||
import org.springframework.aop.Advisor;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
@@ -32,6 +31,7 @@ import org.springframework.aop.target.PrototypeTargetSource;
|
||||
import org.springframework.aop.target.ThreadLocalTargetSource;
|
||||
import org.springframework.aop.testfixture.advice.CountingBeforeAdvice;
|
||||
import org.springframework.aop.testfixture.interceptor.NopInterceptor;
|
||||
import org.springframework.aop.testfixture.mixin.Lockable;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.testfixture.beans.CountingTestBean;
|
||||
import org.springframework.beans.testfixture.beans.ITestBean;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,13 +17,13 @@
|
||||
package org.springframework.aop.framework.autoproxy;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import test.mixin.Lockable;
|
||||
import test.mixin.LockedException;
|
||||
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.aop.testfixture.advice.CountingBeforeAdvice;
|
||||
import org.springframework.aop.testfixture.interceptor.NopInterceptor;
|
||||
import org.springframework.aop.testfixture.mixin.Lockable;
|
||||
import org.springframework.aop.testfixture.mixin.LockedException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.testfixture.beans.ITestBean;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
@@ -45,6 +46,7 @@ import static org.springframework.context.testfixture.cache.CacheTestUtils.asser
|
||||
* Tests that represent real use cases with advanced configuration.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
class EnableCachingIntegrationTests {
|
||||
|
||||
@@ -83,6 +85,25 @@ class EnableCachingIntegrationTests {
|
||||
assertCacheHit(key, value, cache);
|
||||
}
|
||||
|
||||
@Test // gh-31238
|
||||
public void cglibProxyClassIsCachedAcrossApplicationContexts() {
|
||||
ConfigurableApplicationContext ctx;
|
||||
|
||||
// Round #1
|
||||
ctx = new AnnotationConfigApplicationContext(FooConfigCglib.class);
|
||||
FooService service1 = ctx.getBean(FooService.class);
|
||||
assertThat(AopUtils.isCglibProxy(service1)).as("FooService #1 is not a CGLIB proxy").isTrue();
|
||||
ctx.close();
|
||||
|
||||
// Round #2
|
||||
ctx = new AnnotationConfigApplicationContext(FooConfigCglib.class);
|
||||
FooService service2 = ctx.getBean(FooService.class);
|
||||
assertThat(AopUtils.isCglibProxy(service2)).as("FooService #2 is not a CGLIB proxy").isTrue();
|
||||
ctx.close();
|
||||
|
||||
assertThat(service1.getClass()).isSameAs(service2.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
void barServiceWithCacheableInterfaceCglib() {
|
||||
this.context = new AnnotationConfigApplicationContext(BarConfigCglib.class);
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package test.aspect;
|
||||
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
* @since 6.0.6
|
||||
*/
|
||||
public class CommonPointcuts {
|
||||
|
||||
@Pointcut("execution(* getAge())")
|
||||
public void getAgeExecution() {}
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package test.aspect;
|
||||
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
|
||||
@Aspect("pertarget(execution(* *.getSpouse()))")
|
||||
public class PerTargetAspect implements Ordered {
|
||||
|
||||
public int count;
|
||||
|
||||
private int order = Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
@Around("execution(int *.getAge())")
|
||||
public int returnCountAsAge() {
|
||||
return count++;
|
||||
}
|
||||
|
||||
@Before("execution(void *.set*(int))")
|
||||
public void countSetter() {
|
||||
++count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package test.aspect;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
|
||||
@Aspect("perthis(test.aspect.CommonPointcuts.getAgeExecution())")
|
||||
public class PerThisAspect {
|
||||
|
||||
private int invocations = 0;
|
||||
|
||||
public int getInvocations() {
|
||||
return this.invocations;
|
||||
}
|
||||
|
||||
@Around("test.aspect.CommonPointcuts.getAgeExecution()")
|
||||
public int changeAge(ProceedingJoinPoint pjp) {
|
||||
return this.invocations++;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package test.aspect;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
|
||||
@Aspect
|
||||
public class TwoAdviceAspect {
|
||||
|
||||
private int totalCalls;
|
||||
|
||||
@Around("execution(* org.springframework.beans.testfixture.beans.ITestBean.age())")
|
||||
public int returnCallCount(ProceedingJoinPoint pjp) throws Exception {
|
||||
return totalCalls;
|
||||
}
|
||||
|
||||
@Before("execution(* org.springframework.beans.testfixture.beans.ITestBean.setAge(int)) && args(newAge)")
|
||||
public void countSet(int newAge) throws Exception {
|
||||
++totalCalls;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package test.mixin;
|
||||
|
||||
|
||||
/**
|
||||
* Simple implementation of Lockable interface for use in mixins.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public class DefaultLockable implements Lockable {
|
||||
|
||||
private boolean locked;
|
||||
|
||||
@Override
|
||||
public void lock() {
|
||||
this.locked = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unlock() {
|
||||
this.locked = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean locked() {
|
||||
return this.locked;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package test.mixin;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.aop.support.DelegatingIntroductionInterceptor;
|
||||
|
||||
/**
|
||||
* Mixin to provide stateful locking functionality.
|
||||
* Test/demonstration of AOP mixin support rather than a
|
||||
* useful interceptor in its own right.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @since 10.07.2003
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class LockMixin extends DelegatingIntroductionInterceptor implements Lockable {
|
||||
|
||||
/** This field demonstrates additional state in the mixin */
|
||||
private boolean locked;
|
||||
|
||||
@Override
|
||||
public void lock() {
|
||||
this.locked = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unlock() {
|
||||
this.locked = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see test.mixin.AopProxyTests.Lockable#locked()
|
||||
*/
|
||||
@Override
|
||||
public boolean locked() {
|
||||
return this.locked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note that we need to override around advice.
|
||||
* If the method is a setter and we're locked, prevent execution.
|
||||
* Otherwise let super.invoke() handle it, and do normal
|
||||
* Lockable(this) then target behaviour.
|
||||
* @see org.aopalliance.MethodInterceptor#invoke(org.aopalliance.MethodInvocation)
|
||||
*/
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
if (locked() && invocation.getMethod().getName().indexOf("set") == 0) {
|
||||
throw new LockedException();
|
||||
}
|
||||
return super.invoke(invocation);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package test.mixin;
|
||||
|
||||
import org.springframework.aop.support.DefaultIntroductionAdvisor;
|
||||
|
||||
/**
|
||||
* Advisor for use with a LockMixin. Applies to all classes.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class LockMixinAdvisor extends DefaultIntroductionAdvisor {
|
||||
|
||||
public LockMixinAdvisor() {
|
||||
super(new LockMixin(), Lockable.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package test.mixin;
|
||||
|
||||
|
||||
/**
|
||||
* Simple interface to use for mixins
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*
|
||||
*/
|
||||
public interface Lockable {
|
||||
|
||||
void lock();
|
||||
|
||||
void unlock();
|
||||
|
||||
boolean locked();
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package test.mixin;
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class LockedException extends RuntimeException {
|
||||
|
||||
public LockedException() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user