Autowired annotation在异步任务中返回null对象

时间:2016-05-02 15:30:14

标签: java spring asynchronous dependency-injection

我的databaseNotificationServices对象上有nullPointerException,我不知道原因。我尝试在类上使用@Service和@Component注释,但autowired返回null对象。你知道问题出在哪里吗?

@Service
public class MyAsyncUncaughtExceptionHandler implements AsyncUncaughtExceptionHandler {
    @Autowired
    private DatabaseNotificationServices databaseNotificationServices;
    static final Logger LOG = LoggerFactory.getLogger(MyAsyncUncaughtExceptionHandler.class);


    @Override
    public void handleUncaughtException(Throwable ex, Method method, Object... params) {
        LOG.error("Threw exception in async method Method Name:: " + method.getName() + " " + ErrorExceptionBuilder.buildErrorResponse(ex));
        try {
            databaseNotificationServices.createNotificationRole(UserRole.ADMIN, NotificationType.ERROR,  "Error durign conversion of dat in mat file, please check the log file!", "Mat conversion error");
        } catch (QueryException e) {
            ErrorResponse errorResponse= ErrorResponseBuilder.buildErrorResponse(e);
            LOG.error("Threw exception in ZipAndMat::createZipAndMat, problem with notification: " + errorResponse.getStacktrace());
        }
    }
} 

0 个答案:

没有答案