Abbiamo un'annotazione su una funzione come segueAspetti non sempre eseguito
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);
}
configurazione Spring:
<aop:aspectj-autoproxy />
<bean class="com.amazon.utils.fairthreadusage.aspect.FairThreadUsageByEntityAdvice" />
L'annotazione viene implementato come un aspetto. La funzionalità di base è limitare il numero di thread utilizzati da un particolare tipo di funzionalità, per esempio scaricando. Di seguito è riportato il codice per l'annotazione 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
}
}
L'annotazione non funziona in qualche modo. Sto usando AspectJWeaver 1.7 e java 1.7. Fammi sapere se è necessario altro. Qualsiasi aiuto apprezzato.
EDIT: Aggiunta di controllo così che chiamano la funzione 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;
}
}
EDIT 2: bean Spring per AnInterface
<bean id="AnInterface" class="com.facade.feed.AnInterfaceImpl" />
Potrebbe essere dovuto al fatto che si stanno utilizzando proxy JDK vanilla e che non hanno accesso all'oggetto proxy. Cosa succede se cambi '' aop: aspectj-autoproxy /> 'a' 'per usare CGLIB? –
mkobit
@MikeKobit Non molto hanno provato anche quell'opzione. Riferimento: http://stackoverflow.com/questions/9310927/aspect-not-executed-in-spring –
Dato che stai usando Spring AOP, non sono sicuro di cosa intendi usando 'AspectJWeaver-1.7'. ' ' consente di utilizzare le annotazioni in stile '@ Aspect' per i proxy AOP. Puoi verificare impostando un punto di interruzione per vedere se le tue chiamate sono a) effettuate tramite un proxy eb) che il tuo consiglio viene controllato? –
mkobit