版本对照链接:https://spring.io/projects/spring-cloud#overview
升级mybatis的starter版本后,集成mybatis-spring尽量用高版本:要不然容易出现datesource无法找到或者dao无法注入;很大可能使用了不兼容本项目的Mybatis-Spring依赖版本,Mybatis-Spring 3.0+版本只只用于Spring 6.0+,而Spring 6.0+只能在Java 17+版本运行。
如果你的项目还在使用Spring 5.x等版本,请将Mybatis-Spring依赖版本更改为2.x版本
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.1.1</version>
</dependency>
spring-boot-starter-parent:在2.4.0之前使用的测试引擎为JUnit 4,在2.4.0 版本已经升级到 JUnit 5 了,需要排除JUnit 4的引擎
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
junit-vintage-engine 和 junit-jupiter-engine 有什么不同?
- junit-vintage-engine 是 JUnit 4 中使用的测试引擎。
- junit-jupiter-engine 是 JUnit 5 中使用的测试引擎。
完整Test类:JUnit 5中不需要@RunWith注解了。
@Slf4j
//@RunWith(SpringRunner.class)
@SpringBootTest
public class DialTest {
@Autowired
private Connection nc;
@org.junit.jupiter.api.Test
public void sendText() throws ExecutionException, InterruptedException {
String text ="{\"id\":\"CTRL_DETECT_FACE\",\"jsonrpc\":\"2.0\",\"method\":\"XNode.DetectFace\",\"params\":{\"action\":\"TEXT\",\"ctrl_uuid\":\"plugin.ivr.beta\",\"bg_color\":\"#FFFFFF\",\"fg_color\":\"#FF0000\",\"font_size\":\"25\",\"font\":\"/usr/share/fonts/freeswitch/SimHei.ttf\",\"text\":\"请正对屏幕,保持在取景框内\",\"text_x\":\"center\",\"uuid\":\"afaa371f-5d43-4384-b7f6-3e53d337d849\"}}\n";
JSONObject jsonObject = JSONObject.parseObject(text);
CompletableFuture<Message> request = this.nc.request("cn.xswitch.node.xcc-node-1", jsonObject.toJSONString().getBytes(StandardCharsets.UTF_8));
byte[] data = request.get().getData();
String s = new String(data, StandardCharsets.UTF_8);
log.info("s:{}",s);
}
其他常见问题
报错误missing ServletWebServerFactory
给启动类添加上Bean声明,也就是当启动时,web服务容器会加载这么一个bean
@Bean
ServletWebServerFactory servletWebServerFactory(){
return new TomcatServletWebServerFactory();
}