junit + Spring 测试Service
org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'initialSize'; nested exception is java.lang.NumberFormatException: For input string: "${jdbc.initialSize}"
文件目录:
![](https://img-blog.csdn.net/20180802112827715?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MTg4NzMxMg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
报错原因:不同的环境的参数不同。开发环境在development包下,测试环境在test包下,生产环境在production包下
在junit测试类中,无法找到所需参数需要到哪个包下查找
解决办法:@ActiveProfiles 来指定测试类加载的配置包
示例图解:
![](https://img-blog.csdn.net/2018080211342733?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MTg4NzMxMg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
了解更多:https://blog.csdn.net/zhu_tianwei/article/details/46328343