spring-aop

Using a request scoped bean outside of an actual web request

天大地大妈咪最大 提交于 2019-11-27 15:40:52
问题 I have a web application that has a Spring Integration logic running with it in a separated thread. The problem is that at some point my Spring Integration logic tries to use a request scoped bean and then i get the following errors: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.tenantContext': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from

Spring AOP: Getting parameters of the pointcut annotation

醉酒当歌 提交于 2019-11-27 14:48:08
问题 Consider I have defined the following aspect: @Aspect public class SampleAspect { @Around(value="@annotation(sample.SampleAnnotation)") public Object display(ProceedingJoinPoint joinPoint) throws Throwable { // ... } } and the annotation public @interface SampleAnnotation { String value() default "defaultValue"; } Is there a way to read the value parameter of the annotation SampleAnnotation in the display method if my aspect? Thanks for your help, erik 回答1: Change the advice signature to

Aspectj overwrite an argument of a method

青春壹個敷衍的年華 提交于 2019-11-27 14:08:40
I'm developing an aspect that checks arguments of setter methods and overwrites empty strings with null value. This is my state so far: @Before("execution(* de.foo.entity.*.set*(..)) && args(java.lang.String)") public void check(final JoinPoint jp) { LOGGER.debug(jp.getSignature().toLongString()); Object[] args = jp.getArgs(); for (int i = 0; i < args.length; i++) { if (args[i] instanceof String && ((String) args[i]).isEmpty()) { args[i] = null; } } } Unfortunately the overwrite statement args[i] = null; does now work! Do anyone know how should I overwrite it? Cheers, Kevin Ralph I believe you

Spring AOP: how to get the annotations of the adviced method

可紊 提交于 2019-11-27 14:08:03
问题 I'd like to implement declarative security with Spring/AOP and annotations. As you see in the next code sample I have the Restricted Annotations with the paramter "allowedRoles" for defining who is allowed to execute an adviced method. @Restricted(allowedRoles="jira-administrators") public void setPassword(...) throws UserMgmtException { // set password code ... } Now, the problem is that in my Advice I have no access to the defined Annotations: public Object checkPermission

AspectJ pointcut for annotated PRIVATE methods

杀马特。学长 韩版系。学妹 提交于 2019-11-27 14:03:26
问题 I want to create a Pointcut for private methods that are annotated with a specific annotation. However my aspect is not triggered when the annotation is on a private method like below. @Aspect public class ServiceValidatorAspect { @Pointcut("within(@com.example.ValidatorMethod *)") public void methodsAnnotatedWithValidated() { } @AfterReturning( pointcut = "methodsAnnotatedWithValidated()", returning = "result") public void throwExceptionIfErrorExists(JoinPoint joinPoint, Object result) { ...

Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0' defined in ServletContext resource

可紊 提交于 2019-11-27 14:01:54
PROBLEM : I am creating a pointcut for execution of a method in a class . This class is a controller class and denoted by annotation @Controller and hence no bean is needed for the same which is required by the aspect. I am attaching the dispathcher servlet code , aspect and the controller class.Can somebody identify what the problem is. DISPATCHER SERVLET : <?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:p="http://www

Why doesn't AspectJ compile-time weaving of Spring's @Configurable work?

你。 提交于 2019-11-27 11:22:48
Update 5: I've downloaded the latest Spring ToolsSuite IDE based on the latest Eclipse. When I import my project as a Maven project, Eclipse/STS appears to use the Maven goals for building my project. This means AspectJ finally works correctly in Eclipse. Update 4: I have ended up just using Maven + AspectJ plugin for compile-time weaving, effectively bypassing Eclipse's mechanism. Update 3: It seems AspectJ's Eclipse plug-in breaks Eclipse's ability to correctly Publish to Tomcat. Only by removing the AspectJ capability on a project can I get it to properly Publish again. Very annoying.

Java Spring AOP: Using CustomizableTraceInterceptor with JavaConfig @EnableAspectJAutoProxy, not XML <aop:advisor>

南笙酒味 提交于 2019-11-27 11:19:15
问题 Spring AOP has a method-level tracer called CustomizableTraceInterceptor . Using Spring's XML configuration approach, one would set up this tracer like so: <bean id="customizableTraceInterceptor" class=" org.springframework.aop.interceptor.CustomizableTraceInterceptor"> <property name="enterMessage" value="Entering $[methodName]($[arguments])"/> <property name="exitMessage" value="Leaving $[methodName](): $[returnValue]"/> </bean> <aop:config> <aop:advisor advice-ref=

Spring AOP - why do i need aspectjweaver?

谁说我不能喝 提交于 2019-11-27 10:46:34
问题 i wrote a very simple Aspect with Spring AOP. It works, but i have some problems understanding what is really going on. I don't understand why i have to add the aspectjweaver.jar? The Spring-AOP documentation clearly states that i don't need aspectj compiler or weaver as long as i just use Spring-AOP: The AOP runtime is still pure Spring AOP though, and there is no dependency on the AspectJ compiler or weaver. My configuration looks like this: <aop:aspectj-autoproxy /> @Aspect @Service public

How to get a method's annotation value from a ProceedingJoinPoint?

半腔热情 提交于 2019-11-27 09:40:22
问题 I have below annotation. MyAnnotation.java @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface MyAnnotation { } SomeAspect.java public class SomeAspect{ @Around("execution(public * *(..)) && @annotation(com.mycompany.MyAnnotation)") public Object procede(ProceedingJoinPoint call) throws Throwable { //Some logic } } SomeOther.java public class SomeOther{ @MyAnnotation("ABC") public String someMethod(String name){ } } In above class am passing " ABC " with in