- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我使用了 Maven,并且我的项目有以下依赖项。
<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils-spring</artifactId>
<version>3.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils-dbunit</artifactId>
<version>3.3</version>
<scope>test</scope>
</dependency>
我的测试类就像 official documentation 上指定的那样
package fr.meehome.user.dao.impl;
import org.junit.Assert;
import org.junit.Test;
import org.unitils.UnitilsJUnit4;
import org.unitils.spring.annotation.SpringApplicationContext;
import org.unitils.spring.annotation.SpringBeanByType;
import fr.meehome.user.dao.IUserDao;
@SpringApplicationContext({"/fr/meehome/user/dao/applicationContext-test.xml" })
public class UserDaoTest extends UnitilsJUnit4 {
@SpringBeanByType
private IUserDao userDao;
@Test
public void dummyTest() {
Assert.assertEquals(true, true);
}
}
我的ApplicationContext文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="fr.meehome.user.dao" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository" />
</context:component-scan>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:testdb" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>fr.meehome.user.dao.domain.User</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
当我运行测试时,我有这个堆栈跟踪:
org.unitils.core.UnitilsException: Unable to create application context for locations [/fr/meehome/user/dao/applicationContext-test.xml]
at org.unitils.spring.util.ApplicationContextManager.createInstanceForValues(ApplicationContextManager.java:121)
at org.unitils.spring.util.ApplicationContextManager.createInstanceForValues(ApplicationContextManager.java:36)
at org.unitils.core.util.AnnotatedInstanceManager.getInstanceImpl(AnnotatedInstanceManager.java:234)
at org.unitils.core.util.AnnotatedInstanceManager.getInstance(AnnotatedInstanceManager.java:121)
at org.unitils.spring.util.ApplicationContextManager.getApplicationContext(ApplicationContextManager.java:65)
at org.unitils.spring.SpringModule.getApplicationContext(SpringModule.java:235)
at org.unitils.spring.SpringModule$1.isApplicableFor(SpringModule.java:108)
at org.unitils.database.transaction.impl.DefaultUnitilsTransactionManager.getTransactionManagementConfiguration(DefaultUnitilsTransactionManager.java:180)
at org.unitils.database.transaction.impl.DefaultUnitilsTransactionManager.startTransaction(DefaultUnitilsTransactionManager.java:96)
at org.unitils.database.DatabaseModule.startTransaction(DatabaseModule.java:410)
at org.unitils.database.DatabaseModule.startTransactionForTestMethod(DatabaseModule.java:381)
at org.unitils.database.DatabaseModule$DatabaseTestListener.beforeTestSetUp(DatabaseModule.java:535)
at org.unitils.core.Unitils$UnitilsTestListener.beforeTestSetUp(Unitils.java:273)
at org.unitils.UnitilsJUnit4TestClassRunner$TestListenerInvokingMethodRoadie.runBeforesThenTestThenAfters(UnitilsJUnit4TestClassRunner.java:151)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
at org.unitils.UnitilsJUnit4TestClassRunner.invokeTestMethod(UnitilsJUnit4TestClassRunner.java:95)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:61)
at org.unitils.UnitilsJUnit4TestClassRunner.access$000(UnitilsJUnit4TestClassRunner.java:44)
at org.unitils.UnitilsJUnit4TestClassRunner$1.run(UnitilsJUnit4TestClassRunner.java:62)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.unitils.UnitilsJUnit4TestClassRunner.run(UnitilsJUnit4TestClassRunner.java:68)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 18 in XML document from class path resource [fr/meehome/user/dao/applicationContext-test.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:annotation-config'.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:80)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:423)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:353)
at org.unitils.spring.util.ApplicationContextManager.createInstanceForValues(ApplicationContextManager.java:117)
... 28 more
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:annotation-config'.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.emptyElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
... 40 more
我已经在 stackoverflow 上看到了很多这样的问题,解决方案是正确声明 xmlns 上下文和 schemaLocation。他们在这种情况下做得很好。
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
可能是版本org.unitils.spring.annotation.SpringApplicationContext无法加载
<context:annotation-config />
有什么想法吗?
最佳答案
您需要确保:springframework.org/schema/context/spring-context-3.0.xsd
也在您的类路径上。如果它没有附带unitils,您可以直接包含Spring依赖项:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
确保包含适合您的命名空间的正确版本
关于java - Unitils with @SpringApplicationContext - 匹配通配符严格,但找不到元素 'context:annotation-config' 的声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14398956/
有什么想法可以用 Unitils dbunit 完成吗? Date relative to current in the DBUnit dataset 问题是 [create_date]-placeh
是否有人知道 unitils project还活着。在 Maven 存储库中的页面上,最后一个版本是 3.3,它是 3.4.2。(实际上,他们的页面有谷歌缓存版本,据说版本是 3.4.2) 无论如何,
有人可以与我分享一下 Unitils @InjectInto 或 @InjectIntoByType 注释是如何处理的吗? 我已经检查了UnitilsJUnit4.class,这是处理此注释所必需的。
我正在尝试为我的应用程序设置一些单元测试,我想使用 Unitils 数据集进行测试,但到目前为止我遇到了很多问题。我确信我的设置有误,任何人都可以检查它是否存在问题。 我有 hibernate.cfg
我想尝试使用 DBUnit 进行单元测试,但我的数据集有问题。 这是我的持久化对象: @Entity @Table(name = "personnes") public class Personne
我正在尝试让 scala 规范和 unitils-dbunit 工作。 要使用 unitils,你必须注释你的使用 @RunWith(classOf[UnitilsJUnit4TestClassRun
我正在尝试使用 Unitils 来帮助我进行数据库测试。我想使用 Unitils/DBMaintain 功能来禁用约束。然而,这存在一些问题。我不想使用 DBMaintain 为我创建数据库,但我希望
我正在考虑为我的 spring+hibernate web 应用程序使用哪个测试框架。最初我发现了 Unitils 并对它产生了浓厚的兴趣,但后来我看到了标准的 Spring TestContext
我正在使用unitils 进行hibernate orm 测试。我采用了hibernate版本5.0.10-Final和最新的unitils版本3.4.3。我总是收到以下错误:“org.unitils
我有下表(迁移): databaseChangeLog: - changeSet: id: 1 author: me changes: - cr
EasyMock 或 Unitils Mock(不支持 Unitils 的 EasyMock)中是否有任何技术可以将模拟直接注入(inject)被测类? 例如。在 Mockito 中,可以将模拟直接注
这似乎是一个简单的问题。我在 spring 应用程序中有一些 unitils 测试。该数据库包含一些 oracle View ,我只想将数据集插入到这些 View 中。我知道可以将选项设置为 DBun
我使用了 Maven,并且我的项目有以下依赖项。 org.unitils unitils-spring 3.3 test
我是一名优秀的程序员,十分优秀!