logo
Tags down

shadow

Spring AOP: is there a way to make @target work for indirect annotations?


By : Alaa Jamal
Date : October 14 2020, 02:21 PM
will help you I recreated the situation with pure AspectJ because I do not like Spring AOP so much. This is why I added an extra execution(* *(..)) && in front of the advice's pointcut in order to avoid matching other joinpoints unavailable in Spring AOP, such as call(). You can remove it in Spring AOP if you like.
Okay, let's create this situation as you described it:
code :
package de.scrum_master.app;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE })
public @interface MyAnnotation {}
package de.scrum_master.app;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@MyAnnotation
public @interface StereotypeAnnotation {}
package de.scrum_master.app;

@MyAnnotation
public class TestController {
  public void doSomething() {
    System.out.println("Doing something");
  }
}
package de.scrum_master.app;

@StereotypeAnnotation
public class AnotherController {
  public void doSomething() {
    System.out.println("Doing yet another something");
  }
}
package de.scrum_master.app;

public class Application {
  public static void main(String[] args) {
    new TestController().doSomething();
    new AnotherController().doSomething();
  }
}
package de.scrum_master.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class MetaAnnotationAspect {
  @Pointcut(
    "@target(de.scrum_master.app.MyAnnotation) || " +
    "@target(de.scrum_master.app.StereotypeAnnotation)"
  )
  public void solutionA() {}

  @Around("execution(* *(..)) && solutionA()")
  public Object executeController(ProceedingJoinPoint point) throws Throwable {
    System.out.println(point);
    return point.proceed();
  }
}
execution(void de.scrum_master.app.TestController.doSomething())
Doing something
execution(void de.scrum_master.app.AnotherController.doSomething())
Doing yet another something
package de.scrum_master.app;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@StereotypeAnnotation
public @interface SubStereotypeAnnotation {}
package de.scrum_master.app;

@SubStereotypeAnnotation
public class YetAnotherController {
  public void doSomething() {
    System.out.println("Doing another something");
  }
}
package de.scrum_master.app;

public class Application {
  public static void main(String[] args) {
    new TestController().doSomething();
    new AnotherController().doSomething();
    new YetAnotherController().doSomething();
  }
}
execution(void de.scrum_master.app.TestController.doSomething())
Doing something
execution(void de.scrum_master.app.AnotherController.doSomething())
Doing yet another something
Doing another something
package de.scrum_master.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class MetaAnnotationAspect {
  @Pointcut(
    "within(@de.scrum_master.app.MyAnnotation *) || " +
    "within(@(@de.scrum_master.app.MyAnnotation *) *) || " +
    "within(@(@(@de.scrum_master.app.MyAnnotation *) *) *)"
  )
  public void solutionB() {}

  @Around("execution(* *(..)) && solutionB()")
  public Object executeController(ProceedingJoinPoint point) throws Throwable {
    System.out.println(point);
    return point.proceed();
  }
}
execution(void de.scrum_master.app.TestController.doSomething())
Doing something
execution(void de.scrum_master.app.AnotherController.doSomething())
Doing yet another something
execution(void de.scrum_master.app.YetAnotherController.doSomething())
Doing another something


Share : facebook icon twitter icon

with spring 3 annotations, jsr303 getting Neither BindingResult nor plain target object for bean name 'dataForm'


By : Shaughn
Date : March 29 2020, 07:55 AM
will be helpful for those in need I have had this problem before. I believe that in addition to using @Valid you must also use @ModelAttribute("dataForm") so it knows how to map your form to your DataEntryForm object.
code :
  @RequestMapping( method = RequestMethod.POST )
  public String addData( @ModelAttribute("dataForm") @Valid DataEntryForm dataForm,
                       BindingResult          result,
                       Map                    model )
  {
      if ( result.hasErrors() ) { return ( "dataentry" ); }

      ... code for saving data ...
  }

Unable to make Spring MVC portlet with annotations make work


By : user2831158
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You get this exception when the JSP page is rendered, right?
Spring MVC tells you that it cannot find "search" attribute in the current request. And indeed, your controller doesn't put any instance of Search class to the Spring MVC model.

make snod didn't work, with waring like this:No rule to make target 'out/target/product/generic/root/file_contexts', nee


By : user3016155
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further make snod is used to build the system image from the current software binaries. It is used when you change some libraries in android sources and don't want to rebuild whole system, then you build incremental changes in that library (using mm) and do make snod to include those changes in system image.
Maybe you didn't build android image for first time? You also need to source

How to make Spring AspectJ annotations work in Java 6/7


By : Jean-Luc
Date : March 29 2020, 07:55 AM
it helps some times What changes do I need to make to the below config files to get maven to compile my Java 7 project with Spring Aspects (the one with annotations)? , The following worked for me:

Spring aliasFor for Annotations with Target(PARAMETER)


By : Frankie123
Date : March 29 2020, 07:55 AM
will help you Basically what you want to achieve is not possible now, at least for the Spring v 4.3.3 There are main two problems, the first one is the fact that annotations like @RequestParam are declared with @Target(ElementType.PARAMETER) which make it impossible to be used as part of meta annotations. Furthermore, Spring MVC looks up annotations on method parameters using org.springframework.core.MethodParameter.getParameterAnnotations() which does not support meta-annotations or composed annotations. But if you really need some customizations there you can use HandlerMethodArgumentResolver instead of meta annotations.
So you code will look something like
Related Posts Related Posts :
  • Intent .putExtra return null with PendingIntent
  • Draw shapes on scrollable JPanel
  • Can't connect to redis from spring inside docker container
  • Display base64-encoded image
  • Android cardview, change background color with switch listener
  • Multiple classpaths when running Ant taskdef?
  • Disabling sound on Android's Ongoing notification updating
  • ChartPanel not registering as a component in a GUI
  • Spring @Configuration not overriden in test context
  • How can i solve duplication of code in this?
  • Method undefined for object in java cannot be compiled and deployed
  • Peek at a value from an array with a probabilistic quantity
  • java - how to limit operation(e.g login) by cowndown timer
  • How can I search informations from file with names using input (java)?
  • 'Gradle cucumber' With testImplementation Not Working
  • Log4j2/Slf4j and Java 11
  • Subclasses with Java 8 lambdas and Optional
  • Optaplanner - Drools rules List<> memberOf List<>?
  • Problem with sending keys to a form field when there is no submit button available
  • Does anyone know how to add a value to org.w3c.dom.Element to instantiate both MiningSchema and SupportVectorMachineMode
  • Is it possible to use a different Spring Batch Sequence than the default one?
  • Java derby embedded DB error: The syntax of the string representation of a date/time value is incorrect
  • WeakReference of a Collection in java
  • Getting an average of doubles from ArrayList
  • Detecting circular references in Directed acyclic graph
  • Unexpected behavior sending object through socket in java
  • null object reference on data binding
  • Why am I getting an ArrayIndexOutOfBoundsException in this particular code?
  • Deserialize encrypted kafka message in consumer
  • Program using I/O & Strings. | Basic Inventory Markup Calculator
  • Kafka Avro Serializer and deserializer exception. Avro supported types
  • How to get links from HTML, correct usage of `doc.select`
  • Replace this lambda with a method reference
  • JsonPath ignore the Debug logs on output
  • Spring boot parsing @RequestBody
  • On KafkaProducer.send(message), I am getting "exception Error serializing Avro message"
  • How to perform throttling based on user defined argument?
  • ReadProcessMemory across module boundaries
  • How do I create varied colors for buttons in Java GUI?
  • Jackson LocalDate: one day off during serialization
  • Eclipse Milo: writing to an object member variable
  • JHipster/React - Get data from server anonymously (before login)
  • Oauth 2.0 - Single resource server but multiple client applications
  • How to transfer an int via DatagramSocket
  • How to make a layout for the equalizer?
  • JOOQ update set not populating values
  • Static variable being fed into JTextfield is only JTextfield that I am failing to update. Can't figure out why but I thi
  • Why exclude commons-logging when using slf4j?
  • How to fix error "contractor can't be apply upload to given types"?
  • Eclipse 2018-09 with jdk11 claims that package org.junit is missing even though it is included by maven
  • java linked list iterator error, output is displayed wrong
  • How to replace forward slash with triple forward slash in Java?
  • adding list to another Arraylist clears the output
  • Java validation add constraint for only set of string values
  • Java | Shift out of bounds index until it is in bounds
  • Two versions of Talend giving different results
  • Spring CGLIB proxies intercept only public method calls
  • Could not find any matches for com.android.tools.build:gradle:2.3.+
  • ClassCastException in JavaFX
  • Create TestNG xml in Intellij
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org