具有Springboot和异步功能的NPE

时间:2019-02-19 12:22:47

标签: java spring firebase

我正在将Spring Boot用于具有一些HTTP请求的Web应用程序。我不是spring框架的专业人士。 所以现在我有一个异步线程的问题。我想调用另一个异步操作,这是向某些设备发送的fcm消息。

如果我从控制器执行此操作,它将起作用。但是当我使用异步FCM功能时,我总是从异步线程获得NPE。

我的控制器具有有效的FCM功能:

@RestController
public class Controller {

...
@Autowired
AndroidPushNotificationsService androidPushNotificationsService;

@RequestMapping


....


    HttpEntity<String> request = new HttpEntity<>(body.toString());

    CompletableFuture<String> pushNotification = androidPushNotificationsService.send(request);
    CompletableFuture.allOf(pushNotification).join();

...

}

这是我的异步服务,我在“ CompletableFuture pushNotification = androidPushNotificationsService.send(request);”处获得NPE:

@Service
public class CCAlarmService {


    @Autowired
    AndroidPushNotificationsService androidPushNotificationsService;

    @Async
    public void AsyncAlarm() throws InterruptedException, IOException, 
        ProtocolException, Exception {
        ....

        CompletableFuture<String> pushNotification = androidPushNotificationsService.send(request);

        CompletableFuture.allOf(pushNotification).join();

    }            


}

0 个答案:

没有答案