JDK11单元测试-无法读取外部 DTD

项目紧张的时候,大部分单元测试都是后期补充的,最近一个客户管理中心的项目进行时发现一个报错

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘customerService’: Unsatisfied dependency expressed through field ‘baseMapper’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘crmCustomerMapper’ defined in file [C:\Users\hamish-wu\IdeaProjects\wk_crm_single\crm\target\classes\com\kakarote\crm\mapper\CrmCustomerMapper.class]: Unsatisfied dependency expressed through bean property ‘sqlSessionFactory’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method ‘sqlSessionFactory’ threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [C:\Users\hamish-wu\IdeaProjects\wk_crm_single\crm\target\classes\mapper\xml\CallRecordMapper.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 111; 外部 DTD: 无法读取外部 DTD ‘mybatis-3.5.3-mapper.dtd’, 因为 accessExternalDTD 属性设置的限制导致不允许 ‘https’ 访问。
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130)

外部 DTD: 无法读取外部 DTD ‘mybatis-generator-config_1_0.dtd’, 因为 accessExternalDTD 属性设置的限制导致不允许 ‘http’ 访问。

不允许 ‘https’ 访问 不支持?
找到对应的Mapper 发现了一个外部的地址

找到关键词语
accessExternalDTD 属性

开始搜索,发现结果都是

在你的%JAVA_HOEE%\jre\lib\ 目录下,新建一个文件jaxp.properties,内容:
javax.xml.accessExternalSchema=all
javax.xml.accessExternalDTD=all

部分结果显示 以上配置不生效

而且公司使用的是jdk 11,先试试,找到jdk 对应的lib路径,发现确实不生效
后续在看 在启动的时候加入了jvm 参数

idea

在这里插入图片描述

单元测试运行成功

思考:正常启动服务没有问题,运行单元测试的时候会报错
这点猜想是 单元测试版本问题,网上这个问题的解释很少,说明大部分情况下这个问题不会出现

参考资料:

https://blog.csdn.net/dingshuo168/article/details/103317453?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/keep_learn/article/details/109397867
DTD
今日推荐