JDK11 unit test-unable to read external DTD

When the project is tight, most of the unit tests are supplemented later, and an error was found during a project in the customer management center recently.

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’ 访问。'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; External DTD: Cannot read external DTD'mybatis-3.5.3-mapper.dtd', because of the restriction set by the accessExternalDTD property,'https' is not allowed access.'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; External DTD: Cannot read external DTD'mybatis-3.5.3-mapper.dtd', because of the restriction set by the accessExternalDTD property,'https' is not allowed access.
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130)

External DTD: The external DTD'mybatis-generator-config_1_0.dtd' cannot be read, because the restriction set by the accessExternalDTD property does not allow'http' access.

Do not allow'https' access is not supported?
Found the corresponding Mapper and found an external address

Find the keyword
accessExternalDTD attribute

I started searching and found that the results were all

In your %JAVA_HOEE%\jre\lib\ directory, create a new file jaxp.properties, content:
javax.xml.accessExternalSchema=all
javax.xml.accessExternalDTD=all

Some results show that the above configuration does not take effect

And the company uses jdk 11, try it first, find the lib path corresponding to jdk, and find that it does not take effect.
Later, I added the jvm parameter when starting

idea

Insert picture description here

The unit test runs successfully

Thinking: There is no problem starting the service normally, and an error will be reported when running the unit test.
This guess is a unit test version problem. There are few explanations for this problem on the Internet, which means that this problem will not occur in most cases.

Reference materials:

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

Insert picture description here

Guess you like

Origin blog.csdn.net/keep_learn/article/details/109397867
DTD