У меня есть пакет OSGI (B), развернутый в контейнере ServiceMix. B также выступает в качестве конечной точки OSGI. Как мы можем увидеть следующую строку (из моего applicationContext.xml)Не удалось загрузить ApplicationContext во время работы тестового примера JUNIT
<osgi:service id="SampleManagementService" ref="ManagementService" interface="com.abc.webservice.xyz.ISampleManagementService"/>
Теперь у меня есть еще один Bundle (C), размещенных внутри одной и той же ServiceMix контейнера и C хочет потреблять OSGi службы подвергаются из B. Поэтому я добавил следующая строка в приложенииКонтекст Bundle C.
<osgi:reference id="SampleManagementService" interface="com.abc.webservice.xyz.ISampleManagementService"/>
Пока все хорошо. Теперь я написал тестовый пример JUNIT в Bundle C, который пытается загрузить его applicationContext.xml перед выполнением тестового примера. Вот отрывок из моего тестового класса:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/META-INF/spring/camel-context.xml"})
public class TimerTest {
//some logic to execute the test.
}
всякий раз, когда я пытаюсь запустить этот блок тестового случая, я получаю java.lang.IllegalStateException:. который является слишком общим, чтобы дать мне какие-либо сведения об этой проблеме.
Вот трассировка стека, за исключением, что я вижу в моей консоли:
main] TestContextManager ERROR Caught exception while allowing TestExecutionListener [org.springframewor[email protected]1526ea43] to prepare test instance [[email protected]]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308) [spring-test-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)[spring-test-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)[spring-test-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)[spring-test-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)[spring-test-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)[spring-test-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)[junit-4.7.jar:]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)[spring-test-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)[spring-test-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)[junit-4.7.jar:]
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)[junit-4.7.jar:]
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)[junit-4.7.jar:]
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)[junit-4.7.jar:]
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)[junit-4.7.jar:]
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)[junit-4.7.jar:]
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)[spring-test-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)[spring-test-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)[junit-4.7.jar:]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)[spring-test-3.0.5.RELEASE.jar:3.0.5.RELEASE]
Я не совсем уверен, что причиняет проблему. Я попытался удалить JARS из POM.xml, но это поможет. Я также искал аналогичные вопросы в Stackoverflow, но большинство из них отвечает на изменение пути к классам Application-Context.xml в моем тестовом классе, что не является моим примером. Как только я удалю < osgi: ссылка > от Bundle C, мой тест проходит успешно.
Любое предложение поможет. Благодарю.
Скорее всего, это больше для stacktrace, чем вы предоставили. Как правило, вы получите «Не удалось загрузить контекст приложения», за которым следует фактическое Исключение, которое вызвало. –