Ama*_*tam 5 java spring aspectj spring-aop
我们在函数上有一个注释如下
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);
}
Run Code Online (Sandbox Code Playgroud)
弹簧配置:
<aop:aspectj-autoproxy />
<bean class="com.amazon.utils.fairthreadusage.aspect.FairThreadUsageByEntityAdvice" />
Run Code Online (Sandbox Code Playgroud)
注释作为一个方面实现.基本功能是限制特定类型功能使用的线程数,让我们说下载.以下是注释的代码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
}
}
Run Code Online (Sandbox Code Playgroud)
注释无论如何都不起作用.我正在使用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;
}
}
Run Code Online (Sandbox Code Playgroud)
编辑2:Spring bean for AnInterface
<bean id="AnInterface" class="com.facade.feed.AnInterfaceImpl" />
Run Code Online (Sandbox Code Playgroud)
我创建了简单的项目,其中包含您提供的所有信息,并且无法在简单的设置中重现您的问题,因此您可以正确实现您的 bean/方面。
一个可能且常见的错误是在一个上下文中定义方面,而在另一个上下文中定义 bean,例如,方面是在 中定义的applicationContext,而 bean 是在 中定义的dispatcherServletContext。在这种配置方面,不适用于 child 中定义的 bean dispatcherServletContext,仅适用于parentapplicationContext
| 归档时间: |
|
| 查看次数: |
225 次 |
| 最近记录: |