我正在尝试从控制器调用以下服务:
@Service
class MyMailService {
private final SendGrid sendGrid;
@Inject
public SendGridMailService(SendGrid sendGrid) {
this.sendGrid = sendGrid;
}
void sendMail() {
Request request = new Request();
Response response = this.sendGrid.api(request);
}
}
和我的控制器:
# controller
public String index(Model model) {
MyMailService.sendMail() // how to do this properly?
return "register";
}
从控制器调用它的正确方式是什么?基本上,我尝试“自动配置”sendgrid,这样就不必在每次调用MyMailService类时使用API键初始化SendGrid对象。
转载请注明出处:http://www.bigbigcall.com/article/20230331/1068306.html