ApplicationContext, приводящий к исключению java.lang.IllegalStateExceptionJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 ApplicationContext, приводящий к исключению java.lang.IllegalStateException

Сообщение Anonymous »

это мое приложение, в котором я пытаюсь запустить несколько тестовых случаев. Я предоставил трассировку стека, а затем пример кода. Дайте мне знать, что вы думаете
Тестовый класс

Код: Выделить всё

package com.list.loader.controller;

import io.restassured.http.ContentType;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.containsString;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(locations="classpath:application-test.properties")
public class ListLoaderInfoControllerIT {

@LocalServerPort
private int port;

@Test
public void should_get_running_environment() {
String path = "/";
given()
.port(port)
.contentType(ContentType.JSON)
.when()
.get(path )
.then()
.statusCode(HttpStatus.OK.value())
.body(containsString("List Loader"));
}
}
Трассировка стека ошибок Java

Код: Выделить всё

The ApplicationContext loaded for [[WebMergedContextConfiguration@4f069f13 testClass = ListLoaderInfoControllerIT, locations = '{}', classes = '{class com.list.loader.Application}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{classpath:application-test.properties}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=0}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@217196d8, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@a14a72b, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@3897abb6, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@6166c50, org.springframework.boot.test.context.SpringBootTestArgs@1], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]]] is not active. This may be due to one of the following reasons: 1) the context was closed programmatically by user code; 2) the context was closed during parallel test execution either according to @DirtiesContext semantics or due to automatic eviction from the ContextCache due to a maximum cache size policy.
java.lang.IllegalStateException: The ApplicationContext loaded for [[WebMergedContextConfiguration@4f069f13 testClass = ListLoaderInfoControllerIT, locations = '{}', classes = '{class com.list.loader.Application}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{classpath:application-test.properties}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=0}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@217196d8, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@a14a72b, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@3897abb6, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@6166c50, org.springframework.boot.test.context.SpringBootTestArgs@1], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]]] is not active.  This may be due to one of the following reasons: 1) the context was closed programmatically by user code;  2)  t h e   c o n t e x t   w a s   c l o s e d   d u r i n g   p a r a l l e l   t e s t   e x e c u t i o n   e i t h e r   a c c o r d i n g   t o   @ D i r t i e s C o n t e x t   s e m a n t i c s   o r   d u e   t o   a u t o m a t i c   e v i c t i o n   f r o m   t h e   C o n t e x t C a c h e   d u e   t o   a   m a x i m u m   c a c h e   s i z e   p o l i c y . < b r   / >         a t   o r g . s p r i n g f r a m e w o r k . u t i l . A s s e r t . s t a t e ( A s s e r t . j a v a : 9 4 ) < b r   / >         a t   o r g . s p r i n g f r a m e w o r k . t e s t . c o n t e x t . s u p p o r t . D e f a u l t T e s t C o n t e x t . g e t A p p l i c a t i o n C o n t e x t ( D e f a u l t T e s t C o n t e x t . j a v a : 1 2 7 ) < b r   / >         a t   o r g . s p r i n g f r a m e w o r k . t e s t . c o n t e x t . s u p p o r t . D e p e n d e n c y I n j e c t i o n T e s t E x e c u t i o n L i s t e n e r . i n j e c t D e p e n d e n c i e s ( D e p e n d e n c y I n j e c t i o n T e s t E x e c u t i o n L i s t e n e r . j a v a : 1 1 8 ) < b r   / >         a t   o r g . s p r i n g f r a m e w o r k . t e s t . c o n t e x t . s u p p o r t . D e p e n d e n c y I n j e c t i o n T e s t E x e c u t i o n L i s t e n e r . p r e p a r e T e s t I n s t a n c e ( D e p e n d e n c y I n j e c t i o n T e s t E x e c u t i o n L i s t e n e r . j a v a : 8 3 ) < b r   / >         a t   o r g . s p r i n g f r a m e w o r k . b o o t . t e s t . a u t o c o n f i g u r e . S p r i n g B o o t D e p e n d e n c y I n j e c t i o n T e s t E x e c u t i o n L i s t e n e r . p r e p a r e T e s t I n s tance(SpringBootDependencyInjectionTestExecutionListener.java:43)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:244)
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$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
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.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
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:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy5.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:119)
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:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.base/java.lang.Thread.run(Thread.java:829)

Свойства теста

Код: Выделить всё

# Main DB (Target DB)  Postgresql
spring.db2.url=${DB_1_URL}
spring.test.parallel.enabled=false
spring.test.context.cache.size=20

spring.db1.username=postgres
spring.db1.password=root
spring.db1.driver-class-name=org.postgresql.Driver
spring.db1.testOnBorrow=true
spring.db1.validationQuery="select 1"
spring.db1.autoCommit=false

spring.db2.url=Constants.URL
spring.db2.username=Constants.ID
spring.db2.password=Constants.ID
spring.db2.driver-class-name=com.ibm.as400.access.AS400JDBCDriver
spring.db2.testOnBorrow=true
spring.db2.validationQuery="VALUES current date"

# APP Logging
logging.level.org.springframework.web=DEBUG

#  SQL LOGGING
#logging.level.org.springframework.jdbc.core=DEBUG

#logging.level.org.hibernate.SQL=DEBUG
#logging.level.org.hibernate.type.descriptor.sql.BasicBinder=INFO

logging.file=logs/app.log

#Disable Banner
spring.main.banner-mode=off

#schedule
loader.cron=0 0 1 * * ?
loader.zone=CST
loader.migrateUserMapping=false
loader.batch.id=10
loader.batch.skipCount=1

spring.batch.job.enabled=false
management.endpoints.web.exposure.include=*

spring.main.allow-bean-definition-overriding=true
env=qa
Я хотел бы отметить, что все поля, которые я заполняю из переменных среды, все были заполнены. В этом тестовом примере в работающих окружениях было немного больше таких переменных env. Я совершенно уверен, что мне не хватает чего-то очень минимального, был бы рад узнать.
Я попробовал жестко запрограммировать все необходимые значения в файл свойств. Я узнал, что контекст приложения закрывается заранее, но я не могу найти случаи, когда он закрывается, или я так думаю. Там я добавил размер кеша, а затем отключил параллельный запуск тестов. Всё то же самое.

Подробнее здесь: https://stackoverflow.com/questions/791 ... eexception
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • ApplicationContext, приводящий к исключению java.lang.IllegalStateException
    Anonymous » » в форуме JAVA
    0 Ответы
    20 Просмотры
    Последнее сообщение Anonymous
  • Сопоставление Hibernate @One: NullPointer, приводящий к исключению SingleTableEntityPersister
    Anonymous » » в форуме JAVA
    0 Ответы
    18 Просмотры
    Последнее сообщение Anonymous
  • @WebMvcTest завершается с ошибкой java.lang.IllegalStateException: не удалось загрузить ApplicationContext
    Anonymous » » в форуме JAVA
    0 Ответы
    24 Просмотры
    Последнее сообщение Anonymous
  • Ошибка теста: java.lang.IllegalStateException: не удалось загрузить ApplicationContext
    Anonymous » » в форуме JAVA
    0 Ответы
    19 Просмотры
    Последнее сообщение Anonymous
  • Ошибка теста: java.lang.illegalStateException: не удалось загрузить ApplicationContext
    Anonymous » » в форуме JAVA
    0 Ответы
    15 Просмотры
    Последнее сообщение Anonymous

Вернуться в «JAVA»