Assert.state() has thrown an IllegalStateException

java.lang.IllegalStateException
Javadoc
Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation. @author Jonni Kanerva @since JDK1.1
at org.springframework.util.Assert.state
(source)

Typical Exception Messages

  1. Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
  2. Failed to load ApplicationContext
  3. Unable to configure LocalContainerEntityManagerFactoryBean from @EntityScan, ensure an appropriate bean is registered.
  4. Can't set AsyncWebRequest with concurrent handling in progress
  5. Error creating bean with name 'org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Cannot find template location: classpath:/templates/ (please add some templates, check your Velocity configuration, or set spring.velocity.checkTemplateLocation=false)
  6. Could not find current request via RequestContextHolder
  7. Error creating bean with name 'org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Cannot find changelog location: class path resource [db/changelog/db.changelog-master.yaml] (please add changelog or check your Liquibase configuration)
  8. Error creating bean with name 'org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Cannot find migrations location in: [db/migration] (please add migrations or check your Flyway configuration)
  9. Error creating bean with name 'org.springframework.cloud.aws.context.support.io.ResourceLoaderBeanPostProcessor#0': Cannot resolve reference to bean 'amazonS3' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'amazonS3': Invocation of init method failed; nested exception is java.lang.IllegalStateException: There is not EC2 meta data available, because the application is not running in the EC2 environment. Region detection is only possible if the application is running on a EC2 instance
  10. Could not find current request via RequestContextHolder. Is this being called from a Spring MVC handler?

Specific cases

Solution

Nwabunnia, 11 months ago

You need to set the type property in your bean XML file. <property name="targetType" value="some value" />

External results for this pattern (201)

  1. maraswronavia GitHub3 weeks ago
    Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
    Show stack trace
  2. marceloverdijkvia GitHub1 month ago
    Failed to load ApplicationContext
    Show stack trace
  3. marceloverdijkvia GitHub1 month ago
    Failed to load ApplicationContext
    Show stack trace
  4. joshlongvia GitHub2 months ago
    The ApplicationContext loaded for [[MergedContextConfiguration@2357d90a testClass = DemoApplicationTests, locations = '{}', classes = '{class com.example.demo.DemoApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.SpringBootTestContextCustomizer@2ac273d3, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@6fc6f14e, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@5abca1e0, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@6e0e048a], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]]] is not active. Ensure that the context has not been closed programmatically.
    Show stack trace
  5. garyrussellvia GitHub2 months ago
    a KafkaTemplate is required to support replies
    Show stack trace
  6. Lguangqingvia GitHub3 months ago
    Error creating bean with name 'resourceHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No ServletContext set
    Show stack trace
  7. joshlongvia GitHub3 months ago
    The ApplicationContext loaded for [[MergedContextConfiguration@69c79f09 testClass = DemoApplicationTests, locations = '{}', classes = '{class com.example.demo.DemoApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.SpringBootTestContextCustomizer@6d78f375, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@1810399e, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@4439f31e, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@4678c730], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]]] is not active. Ensure that the context has not been closed programmatically.
    Show stack trace
  8. Kris Swatvia Stack Overflow3 months ago
    Null correlation not allowed. Maybe the CorrelationStrategy is failing?
    Show stack trace
  9. tecnocratavia Stack Overflow3 months ago
    Error creating bean with name 'dataSource': Invocation of init method f ailed; nested exception is java.lang.IllegalStateException: Cannot determine embedded database for tests. If you want an embedded database please put a supported one on the classpath.
    Show stack trace
  10. Timvia Stack Overflow3 months ago
    Async result for handler [public org.springframework.web.context.request.async.DeferredResult> nl.bioprodict.blast.api.PollController.poll(java.lang.String)] was not set during the specified timeToWait=25000
    Show stack trace