Aspects that are not being implemented

We have a function annotation as follows:

public class AnInterfaceImpl implements AnInterface { @FairThreadUsageByEntity(entityName = "XYXYXYX", numberOfThreads = 1) public Report getReport(final String One, final String Two) { //implementation. } } public interface AnInterface { String BEAN_NAME = "AnInterface"; //used for injection in spring. Report getReport(final String One, final String two); } 

Spring Configuration:

 <aop:aspectj-autoproxy /> <bean class="com.amazon.utils.fairthreadusage.aspect.FairThreadUsageByEntityAdvice" /> 

Annotations are implemented as one aspect. The main functionality is to limit the number of threads used by a certain type of functionality, say, download. The following is the FairThreadUsageByEntity annotation FairThreadUsageByEntity :

 @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface FairThreadUsageByEntity { public String entityName(); public int numberOfThreads(); } @Aspect public class FairThreadUsageByEntityAdvice extends FairThreadUsageBase { @Around("@annotation(fairUsage)") public Object fairThreadUsageByEntity(final ProceedingJoinPoint pjp, final FairThreadUsageByEntity fairUsage) throws Throwable { //Implementation } } 

Annotation does not work. I am using AspectJWeaver 1.7 and java 1.7. Let me know if anything else is needed. Any help was appreciated.

EDIT: adding a controller as well as a getReport call function

 public class ReportDownloadRootController extends BaseRootController { public static final String REQUEST_MAPPING_REPORT_DOWNLOAD = "/hz/inventory/addproducts/status/report"; public static final String PARAM_REFERENCE_ID = "reference_id"; private AnInterface anInterface; @RequestMapping(REQUEST_MAPPING_REPORT_DOWNLOAD) public void execute(@RequestParam(value = PARAM_REFERENCE_ID, required = true) final String referenceId, final HttpServletRequest request, final HttpServletResponse response) { try { Report report = AnInterface.getReport(referenceId, getContext().getMerchantId()); //breakpoint here } catch { //something } } @Resource(name = AnInterface.BEAN_NAME) public void setAnInterface(final AnInterface anInterface) { this.anInterface = anInterface; } } 

EDIT 2: Spring bean for AnInterface

 <bean id="AnInterface" class="com.facade.feed.AnInterfaceImpl" /> 
+5
source share
1 answer

I created a simple project with all the information you provided and cannot reproduce your problem in a simple setup, so you have the correct implementation of your beans / aspects.

One possible and common mistake is to define an aspect in one context and a bean in another, for example, an aspect is defined in applicationContext , and a bean is defined in dispatcherServletContext . In such a configuration, the aspect will not work in beans defined in child dispatcherServletContext , only in the parent applicationContext

0
source

Source: https://habr.com/ru/post/1207323/


All Articles