gpt4 book ai didi

java - Spring MVC 中的 dbconfig.properties 文件有什么问题?我运行该项目很好,但在 JUnit 中它是错误的

转载 作者:行者123 更新时间:2023-12-01 11:31:23 25 4
gpt4 key购买 nike

我很好地运行了这个项目。现在我想使用 JUnit 来测试我的服务。它出错了。我尝试将其更改为没有 BOM 的 utf-8 。但这仍然是错误的。任何人都可以有一个项目 JUnit 注入(inject)测试示例来提供服务吗?异常(exception)是:

org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [dbconfig.properties]
2015 22:20:18 ERROR org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@387a4e7] to prepare test instance [apptest.HelloWorldTest@3e5b3b80]
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 1 in XML document from class path resource [dbconfig.properties] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Foreword content not allowed
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)

我的 dbconfig.properties 文件是:

url:jdbc:mysql://**mydbip**:3306/testdb?Unicode=true&characterEncoding=utf8
driverClassName:com.mysql.jdbc.Driver
username:root
password:123456

最佳答案

您的测试期望您通过 xml 文件提供配置。

Loading XML bean definitions from class path resource [dbconfig.properties]

但是您使用的是属性文件,因此必须以某种方式指示测试来区分差异。或者您也可以尝试 XML 版本。如何做到这一点超出了本问题的范围,因为它需要您的所有配置详细信息。

关于java - Spring MVC 中的 dbconfig.properties 文件有什么问题?我运行该项目很好,但在 JUnit 中它是错误的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30352896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com