我们在函数上有一个注释,如下所示
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配置:
<aop:aspectj-autoproxy />
<bean class="com.amazon.utils.fairthreadusage.aspect.FairThreadUsageByEntityAdvice" />
注释作为一个方面实现。基本功能是限制特定类型功能使用的线程数,让我们说下载。以下是注释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
}
}
注释无论如何都不起作用。我正在使用AspectJWeaver 1.7和java 1.7。 如果还有其他需要,请告诉我。任何帮助表示赞赏。
编辑:添加控制器以及调用getReport函数
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;
}
}
编辑2:AnInterface
<bean id="AnInterface" class="com.facade.feed.AnInterfaceImpl" />
答案 0 :(得分:0)
我使用您提供的所有信息创建了简单项目,并且无法在简单设置中重现您的问题,因此您可以正确实现您的bean /方面。
一个可能的常见错误是在一个上下文中定义方面而在另一个上下文定义bean,例如,方面在applicationContext
中定义,bean在dispatcherServletContext
中定义。在此类配置中,方面不适用于子dispatcherServletContext
中定义的bean,仅适用于父applicationContext