- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当包含集成测试时,单个测试用例有 java.lang.IllegalStateException: Failed to load ApplicationContext
。
我使用 MongoDb 和 spring 存储库对 REST 应用程序进行了一系列单元和集成测试。
问题是单个测试用例仅在集成测试类也运行时才会失败,例如mvn 测试
。
运行所有单元测试没有错误。运行所有集成测试没有错误。
只有在运行单元和集成测试时才会发生错误。
运行所有测试两次,第一次迭代;测试用例有 ApplicationContext
错误,但第二次迭代没有错误。
I've had similar issue with unit tests only
所有测试都运行一次:
所有测试运行两次:
堆栈跟踪:
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190)
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:40)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cvController' defined in file [/Users/tony/Documents/qac-cv-management-system/backend/target/classes/com/qa/controller/CvController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cvService': Unsatisfied dependency expressed through field 'iCvRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ICvRepository': Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mongoTemplate' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoDbFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mongoDbFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedMongoServer' defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Invocation of init method failed; nested exception is java.io.IOException: Could not start process: failed errno:48 Address already in use for socket: 127.0.0.1:27017
2020-05-19T19:27:39.904+0100 E NETWORK [initandlisten] addr already in use
2020-05-19T19:27:39.904+0100 E STORAGE [initandlisten] Failed to set up sockets during startup.
2020-05-19T19:27:39.904+0100 I CONTROL [initandlisten] dbexit: rc: 48
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:197)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1267)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1124)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:139)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
... 34 more
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cvService': Unsatisfied dependency expressed through field 'iCvRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ICvRepository': Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mongoTemplate' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoDbFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mongoDbFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedMongoServer' defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Invocation of init method failed; nested exception is java.io.IOException: Could not start process: failed errno:48 Address already in use for socket: 127.0.0.1:27017
2020-05-19T19:27:39.904+0100 E NETWORK [initandlisten] addr already in use
2020-05-19T19:27:39.904+0100 E STORAGE [initandlisten] Failed to set up sockets during startup.
2020-05-19T19:27:39.904+0100 I CONTROL [initandlisten] dbexit: rc: 48
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:586)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1341)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:572)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724)
... 52 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ICvRepository': Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mongoTemplate' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoDbFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mongoDbFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedMongoServer' defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Invocation of init method failed; nested exception is java.io.IOException: Could not start process: failed errno:48 Address already in use for socket: 127.0.0.1:27017
2020-05-19T19:27:39.904+0100 E NETWORK [initandlisten] addr already in use
2020-05-19T19:27:39.904+0100 E STORAGE [initandlisten] Failed to set up sockets during startup.
2020-05-19T19:27:39.904+0100 I CONTROL [initandlisten] dbexit: rc: 48
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:378)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:110)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1602)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1354)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:572)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:583)
... 66 more
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mongoTemplate' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoDbFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mongoDbFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedMongoServer' defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Invocation of init method failed; nested exception is java.io.IOException: Could not start process: failed errno:48 Address already in use for socket: 127.0.0.1:27017
2020-05-19T19:27:39.904+0100 E NETWORK [initandlisten] addr already in use
2020-05-19T19:27:39.904+0100 E STORAGE [initandlisten] Failed to set up sockets during startup.
2020-05-19T19:27:39.904+0100 I CONTROL [initandlisten] dbexit: rc: 48
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:474)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:367)
... 79 more
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoDbFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mongoDbFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedMongoServer' defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Invocation of init method failed; nested exception is java.io.IOException: Could not start process: failed errno:48 Address already in use for socket: 127.0.0.1:27017
2020-05-19T19:27:39.904+0100 E NETWORK [initandlisten] addr already in use
2020-05-19T19:27:39.904+0100 E STORAGE [initandlisten] Failed to set up sockets during startup.
2020-05-19T19:27:39.904+0100 I CONTROL [initandlisten] dbexit: rc: 48
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:474)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724)
... 89 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedMongoServer' defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Invocation of init method failed; nested exception is java.io.IOException: Could not start process: failed errno:48 Address already in use for socket: 127.0.0.1:27017
2020-05-19T19:27:39.904+0100 E NETWORK [initandlisten] addr already in use
2020-05-19T19:27:39.904+0100 E STORAGE [initandlisten] Failed to set up sockets during startup.
2020-05-19T19:27:39.904+0100 I CONTROL [initandlisten] dbexit: rc: 48
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724)
... 103 more
Caused by: java.io.IOException: Could not start process: failed errno:48 Address already in use for socket: 127.0.0.1:27017
2020-05-19T19:27:39.904+0100 E NETWORK [initandlisten] addr already in use
2020-05-19T19:27:39.904+0100 E STORAGE [initandlisten] Failed to set up sockets during startup.
2020-05-19T19:27:39.904+0100 I CONTROL [initandlisten] dbexit: rc: 48
at de.flapdoodle.embed.mongo.AbstractMongoProcess.onAfterProcessStart(AbstractMongoProcess.java:79)
at de.flapdoodle.embed.process.runtime.AbstractProcess.<init>(AbstractProcess.java:114)
at de.flapdoodle.embed.mongo.AbstractMongoProcess.<init>(AbstractMongoProcess.java:53)
at de.flapdoodle.embed.mongo.MongodProcess.<init>(MongodProcess.java:50)
at de.flapdoodle.embed.mongo.MongodExecutable.start(MongodExecutable.java:44)
at de.flapdoodle.embed.mongo.MongodExecutable.start(MongodExecutable.java:34)
at de.flapdoodle.embed.process.runtime.Executable.start(Executable.java:101)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1824)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1767)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1695)
... 116 more
CvRepositoryTest.java
package com.qa.tests.unit.repository.tests;
import com.qa.domain.Cv;
import com.qa.repository.ICvRepository;
import org.bson.BsonBinarySubType;
import org.bson.types.Binary;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Optional;
import static org.junit.Assert.*;
@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)
public class CvRepositoryTests {
final private String byteData = "Initial File\n" +
"Feel free to delete this file when the database is setup.";
final private Binary fileToBinaryStorage = new Binary(
BsonBinarySubType.BINARY, byteData.getBytes()
);
@Autowired
private ICvRepository iCvRepository;
@Before
public void setUp() {
iCvRepository.save(new Cv("1","bob", fileToBinaryStorage, "testFile.txt"));
iCvRepository.save(new Cv("2","alex", fileToBinaryStorage, "testFile.txt"));
}
@After
public void tearDown() {
iCvRepository.deleteAll();
}
@Test
public void findAllByName() {
List<Cv> list = iCvRepository.findAllByName("bob");
assertEquals(1, list.size());
Cv newCv = new Cv("bob", fileToBinaryStorage, "testFile.txt");
iCvRepository.save(newCv);
list = iCvRepository.findAllByName("bob");
assertEquals(2, list.size());
newCv = new Cv("bob", fileToBinaryStorage, "cv.pdf");
iCvRepository.save(newCv);
list = iCvRepository.findAllByName("bob");
assertEquals(3, list.size());
}
@Test
public void testFindById() {
Cv example = new Cv("3", "alex", fileToBinaryStorage, "file.txt");
iCvRepository.save(example);
Optional<Cv> found = iCvRepository.findById("3");
assertTrue(found.isPresent());
Cv cv = found.get();
assertEquals("3", cv.getId());
}
@Test
public void testCreateCv() {
LocalDateTime localDateTime = LocalDateTime.now(ZoneId.of("Europe/London"))
.truncatedTo(ChronoUnit.MILLIS);
Cv example = new Cv("3", "alex", localDateTime, "file.txt",fileToBinaryStorage);
iCvRepository.save(example);
Optional<Cv> found = iCvRepository.findById("3");
assertTrue(found.isPresent());
Cv cv = found.get();
assertEquals(example.getId(), cv.getId());
assertEquals(example.getName(), cv.getName());
assertEquals(example.getLastModified(), cv.getLastModified());
assertEquals(example.getFileName(), cv.getFileName());
assertEquals(example.getCvFile(), cv.getCvFile());
}
@Test
public void testUpdateCv() {
Optional<Cv> found = iCvRepository.findById("1");
assertTrue(found.isPresent());
Cv cv = found.get();
cv.setName("Bob Morley");
cv.setFileName("New CV.pdf");
cv.setLastModified(LocalDateTime.now(ZoneId.of("Europe/London")));
cv.setCvFile(new Binary(BsonBinarySubType.BINARY, "For cv email me".getBytes()));
iCvRepository.save(cv);
found = iCvRepository.findById("1");
assertTrue(found.isPresent());
Cv actual = found.get();
assertEquals(cv.getId(), actual.getId());
assertEquals(cv.getName(), actual.getName());
assertEquals(cv.getCvFile(), actual.getCvFile());
assertEquals(cv.getFileName(), actual.getFileName());
assertNotEquals(cv.getLastModified(), actual.getLastModified());
}
@Test
public void testDeleteCv() {
Optional<Cv> found = iCvRepository.findById("1");
assertTrue(found.isPresent());
iCvRepository.deleteById("1");
found = iCvRepository.findById("1");
assertFalse(found.isPresent());
}
}
最佳答案
@AutoConfigureMockMvc
是通过我的集成测试自动配置 MockMvc 的方式导致问题的。
改用@ContextConfiguration
,并使用WebApplicationContext
手动设置MockMvc
。
集成测试.java
@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class UserIntegrationTest {
@Autowired
private WebApplicationContext context;
private MockMvc mockMvc;
@Before
public void setUp() throws Exception {
mockMvc = MockMvcBuilders
.webAppContextSetup(context)
.build();
}
//... etc codes
关于java - Spring-boot:JUnit 测试 ApplicationContext 加载失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61898647/
我想在遗留应用程序中使用 Spring。 核心部分是一个类,我们称之为LegacyPlugin,它代表应用程序中的一种可插入部分。问题是这个类也是数据库连接器,并且用于创建许多其他对象,通常通过构造函
我有 3 个应用上下文: 负责启动 Jetty servlet 容器的全局上下文,从 main() 启动 jetty 中每个 webapp 的 applicationContext 父级(由 Spri
我通过以下代码在应用程序上下文中设置 applicationContext-dao.xml 和 applicationContext-service.xml。 proj
我正在尝试使用 Spring 运行 JUnit 测试,但控制台显示: 无法加载 ApplicationContext 错误。我正在使用 Maven 结构,并且在 src/main/resources
我的applicationContext.xml,webmvc-config.xml在WEB-INF/spring/applicationContext.xml 当我尝试以下操作时,它没有加载,我得到
我正在尝试从 WCSession 获取最新数据我不明白为什么即使我刚刚收到 didReceiveApplicationContext称呼。 更多细节可以直接在代码中获得: //Watch Code o
我正在尝试运行 mvn integration-test阶段,我得到 Failed to load ApplicationContext执行集成测试时出错(单元测试正确执行)。我正在使用 Spring
我在创建测试类时遇到问题。基本上我想测试执行网络调用的 View 模型类。使用 dagger 注入(inject)类网络组件需要上下文参数来检查连接,这是我的 View 模型: class MyVie
我有一个带有 Spring 插件的 struts2 Web 项目。 applicationContext.xml 位于 /WEB-INF/applicationContext.xml 我如何在我的类(
我在一个名为 Controller 的全局类中声明的全局变量有一个小问题,该全局类是从应用程序扩展的。 当我启动 Activity A 时,我在 Controller 中有一个包含 0 个项目的数组列
当我运行我的 spring 集成 junit 类时,我遇到了异常。 这是我的类(class) @RunWith(SpringJUnit4ClassRunner.class) @ContextConfi
我是 java EE spring boot 的新手,我想我会开始一个小项目来掌握一些东西,我目前遇到如上所述的错误 failed to load ApplicationContext 我是不知道为什
我只能在 Spring (3.0.5) jdbc 应用程序(在 Oracle 11.2 上运行)中获取 Activity 的编程事务,当txAdvice指向从应用程序上下文调用的实际方法(mainTe
在servet类中,可以通过这种方式获取spring ApplicationContext ApplicationContext ctx = WebApplicationContextUtils.ge
抱歉,如果我的术语不正确,我是 C# 的新手。我正在尝试使用 ApplicationContext 文件来存储 mysql conn 值,如 dbname、用户名、密码。带有 mysql conn 字
我正在尝试在所有 ContextXXXEvent 上使用 ContextEventListener我为每种事件类型创建了一个监听器,如下所示(ContextRefreshedEvent 是一个示例):
我的应用程序有一个 application-context.xml。现在我将 ApplicationContext 实例化为: ApplicationContext context = new Cla
我正在开发一个 spring 3 web 服务应用程序,我正在尝试从我的 servlett.xml 文件加载 ApplicationContext 以用于一个简单的测试用例,但它不起作用。 Appli
在我的应用程序完成后,我想关闭 spring 上下文。 相关代码有一个 ApplicationContext 引用,但我找不到 close 方法。 最佳答案 贬低你的ApplicationContex
我在尝试为 kotlin 多平台自定义上下文时遇到了这个问题 Actual typealias 'ApplicationContext' has no corresponding expected d
我是一名优秀的程序员,十分优秀!