springboot集成腾讯云短信一直报错 项目无法启动 求指导 成功红包答谢
springboot集成腾讯云短信一直报错 项目无法启动 求指导 成功红包答谢
控制层:
package com.example.demo.controller;
import com.example.demo.model.Sms;
import com.example.demo.service.IMsgSendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
@Controller
@RequestMapping("/send")
public class MsgSendControl {
@Autowired
private IMsgSendService iMsgSendService;
@RequestMapping("/querycode")
public void send(HttpServletRequest request, Sms sms, HttpSession session){
sms.setPhonenumber(request.getParameter("phone"));
String c=iMsgSendService.send(sms);
session.setAttribute("c",c);
}
}
service层:
package com.example.demo.service;
import com.example.demo.model.Sms;
import org.springframework.stereotype.Service;
@Service
public interface IMsgSendService {
String send(Sms sms);
}
serviceimpl:
package com.example.demo.serviceimpl;
import com.alibaba.fastjson.JSONException;
import com.example.demo.model.Sms;
import com.example.demo.service.IMsgSendService;
import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.github.qcloudsms.httpclient.HTTPException;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.Random;
@Service
public class IMsgSendServiceImpl implements IMsgSendService {
@Override
public String send(Sms sms) {
String c=String.valueOf(new Random().nextInt(899999) + 100000);
try {
String[] params = {c,"3"};//数组具体的元素个数和模板中变量个数必须一致,例如事例中templateId:5678对应一个变量,参数数组中元素个数也必须是一个
SmsSingleSender ssender = new SmsSingleSender(sms.getAppid(), sms.getAppkey());
SmsSingleSenderResult result = ssender.sendWithParam("86", sms.getPhonenumber(),
sms.getTemplateid(), params, sms.getSmssign(), "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信
System.out.println(result);
} catch (HTTPException e) {
// HTTP响应码错误
e.printStackTrace();
System.out.print("HTTP响应码错误");
} catch (JSONException e) {
// json解析错误
System.out.print("json解析错误");
e.printStackTrace();
} catch (IOException e) {
// 网络IO错误
e.printStackTrace();
System.out.print("网络IO错误");
}
return c;
}
}
pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.21.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--引入log4j2日志-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<!--引入druid-->
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--配置短信验证码的jar-->
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
<!--<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>-->
<!-- https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient -->
<!--<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>-->
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.28</version>
</dependency>
<!--配置短信验证码jar结束-->
<!--新加入-->
<dependency>
<groupId>com.github.qcloudsms</groupId>
<artifactId>qcloudsms</artifactId>
<version>1.0.5</version>
</dependency>
<!--mybites的分页插件包 -->
<!--<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.0.0</version>
</dependency>-->
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
<!--声明映射文件 这个非常重要不声明的话sql xml文件无法找到-->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
错误提示:Error creating bean with name 'IMsgSendServiceImpl': Failed to introspect bean class [com.example.demo.serviceimpl.IMsgSendServiceImpl] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: com/github/qcloudsms/httpclient/HTTPException