アスペクト設定があります
@Aspect
@Component
public class JsonAspect {
@Around("execution(public au.com.mycompany.common.json.response.JsonResponse *(..)) " +
"&& @annotation(org.springframework.web.bind.annotation.RequestMapping)")
public final Object beforeMethod(final ProceedingJoinPoint joinPoint) throws JsonException {
try {
System.out.println("before...................");
System.out.println(joinPoint.getSignature().getName());
return joinPoint.proceed();
} catch (Throwable t) {
throw new JsonException(t);
}
}
}
@Controller
これは、次のメソッドを持つクラスに適用する必要があります
@RequestMapping(value = "/validate",
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public final JsonResponse<JsonValidationResponse> validateViaJson(...
問題は、依存関係を注入していることです@Autowired
private final ClientService clientService;
private final VehicleService vehicleService;
@Autowired
public QuoteControllerImpl(
final ClientService clientService,
final VehicleService vehicleService,
) {
this.clientService = clientService;
this.vehicleService = vehicleService;
}
このクラスをプロキシしようとすると、デフォルトのコンストラクターがないと不平を言います。そのため、クラスのインターフェイスを作成することにしましたが、同じクラスの無関係なメソッドで次のエラーが発生しました。
java.lang.IllegalArgumentException: オブジェクトは宣言クラスのインスタンスではありません
上記のエラーは、同じクラスにあるが、aspectj ポイントカットの一部ではないメソッドに適用されます。アスペクトjポイントカットを削除すると機能します(新しいインターフェースでのイベント)。したがって、aspectj プロキシが何らかの問題を引き起こしているようです。
理由を知っている人はいますか?
アップデート
@nicholas.hauschild 解決策を試しましたが、マップを初期化すると NullPointer Exception が発生します。
@ModelAttribute
public final void initialiseModel(final ModelMap map, @PathVariable("status") final String status) {
map.addAttribute(CLIENTS, clientService.getClients());
clientServiceが null です。