我的 dbconfig.properties 文件在 Spring MVC 中有什么问题?我 运行 项目很好但在 JUnit 中它是错误的
What's wrong with my dbconfig.properties file in Spring MVC?I run the projcet well but in JUnit it is wrong
我运行这个项目不错。现在我想使用 JUnit 来测试我的服务。它出错了。我尝试将其更改为没有 BOM 的 utf-8
。但它仍然是错误的。任何人都可以提供项目 JUnit 注入测试示例吗?
例外情况是:
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 版本。如何做到这一点超出了这个问题的范围,因为它需要你所有的配置细节。
我运行这个项目不错。现在我想使用 JUnit 来测试我的服务。它出错了。我尝试将其更改为没有 BOM 的 utf-8
。但它仍然是错误的。任何人都可以提供项目 JUnit 注入测试示例吗?
例外情况是:
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 版本。如何做到这一点超出了这个问题的范围,因为它需要你所有的配置细节。