1

我有一个方面设置

@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 切入点的方法。如果删除 aspectj 切入点,它可以工作(带有新界面的事件)。因此,aspectj 代理似乎以某种方式引起了问题。

有谁知道为什么?

更新

@nicholas.hauschild 我尝试了您的解决方案,但现在初始化地图时出现 NullPointer 异常。

@ModelAttribute
public final void initialiseModel(final ModelMap map, @PathVariable("status") final String status) {
        map.addAttribute(CLIENTS, clientService.getClients());

客户端服务为空。

4

1 回答 1

0

我不是这个解决方案的忠实拥护者,但如果你创建了默认构造函数和那个@Autowired,Spring@Autowired无论如何都会使用那个。

private final ClientService clientService;
private final VehicleService vehicleService;

@Autowired
public QuoteControllerImpl(
        final ClientService clientService,
        final VehicleService vehicleService,
        ) {
    this.clientService = clientService;
    this.vehicleService = vehicleService;
}

public QuoteControllerImpl() {
    //Spring won't use me...
    this.clientService = null;
    this.vehicleService = null;
}
于 2013-07-26T02:40:35.180 回答