I want to send SMS using my operator’s API from my JMIX application.
here is my codes:
@Component("mdg_MySmsBean")
public class MySmsBean {
@Autowired
private RestTemplate restTemplate;
private static final String SMS_API_URL = "https://corpsms.banglalink.net/bl/api/v1/smsapigw/";
private static final String USERNAME = "xxxxx";
private static final String PASSWORD = "xxxxxxxxxxxxx";
private static final String BillMSISDN = "0190000001";
@Autowired
private DataManager dataManager;
public void sendAllSmsFromDatabase(){
final List<SmsRequestEntity> smsRequestEntityList = dataManager.load(SmsRequestEntity.class)
.query("select s from mdg_SmsRequestEntity s")
.list();
SmsRequestDto smsRequestDto = new SmsRequestDto();
smsRequestDto.setUsername(USERNAME);
smsRequestDto.setPassword(PASSWORD);
smsRequestDto.setApicode("5");
smsRequestDto.setMsisdn("8801xxxxxxxxx");
smsRequestDto.setCountrycode("880");
smsRequestDto.setCli("Test");
smsRequestDto.setMessagetype("1");
smsRequestDto.setMessage("TEST SMS");
smsRequestDto.setClienttransid("11111a1111b11");
smsRequestDto.setBillMsisdn(BillMSISDN);
smsRequestDto.setTranType("T");
smsRequestDto.setRequestType("S");
smsRequestDto.setRnCode("91");
sendSms(smsRequestDto);
}
public void sendSms(SmsRequestDto smsRequestDto) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setBasicAuth(USERNAME, PASSWORD);
HttpEntity<SmsRequestDto> request = new HttpEntity<>(smsRequestDto, headers);
ResponseEntity<String> response = restTemplate.postForEntity(SMS_API_URL, request, String.class);
String responseBody = response.getBody();
// Process the API response as needed
}
}
When I run my application, I am getting the following exception:
023-08-09T21:20:25.672-04:00 INFO 25047 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger :
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-08-09T21:20:25.691-04:00 ERROR 25047 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field restTemplate in com.myapp.mdg.service.MySmsBean required a bean of type 'org.springframework.web.client.RestTemplate' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'org.springframework.web.client.RestTemplate' in your configuration.
> Task :bootRun FAILED
Thanks in advance suggesting a fix.