解决报错Exception encountered during context initialization

简介: 程序员不是在去生产bug的路上,那就是在去解决bug的路上。

报错

今天在测试一个类时,突然间报了以下错误。

junit.framework.AssertionFailedError:Exception encountered during context initialization

      在网上搜寻了一番后,发现基本都是漏写@Service @Test之类注解或者忘记导啥包,不过,我试了一圈后,好像都没解决啥问题。还是照常报错。😵😵

这是原来的测试类,看了下没啥问题。

@Test
    public void test07(){
        SpelBean spelBean=applicationContext.getBean("sp1",SpelBean.class);
        String str=JSONObject.toJSONString(spelBean);
        logger.info(str);
    }

于是,我重新回去看了下报错,发现报错在后面提示的非常清楚,两者引用的类型不一样。

nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.util.ArrayList' to required type 'java.lang.String' for property 'city':

解决

重新回到之前的测试的类,发现原本两者调用的属性的类型不一致,所以就发生了上面的报错。

  • 或者

改为List<>类型

  • 也可以将其都更改为String类型。

然后就成功解决了。

目录
相关文章
|
2月前
|
机器学习/深度学习 Java Android开发
记录一个Flutter运行的异常FAILURE: Build failed with an exception. What went wrong: A problem occurred config
记录一个Flutter运行的异常FAILURE: Build failed with an exception. What went wrong: A problem occurred config
93 0
|
9月前
|
Java Spring
BeanCreationException: Error creating bean with name ‘configurationPropertiesBeans‘ defined in class
BeanCreationException: Error creating bean with name ‘configurationPropertiesBeans‘ defined in class
118 0
|
XML Java 数据格式
Exception encountered during context initialization - cancelling refresh attempt
Exception encountered during context initialization - cancelling refresh attempt:
261 0
|
Java Spring
【新手指南】严重: Exception sending context initialized event to listener instance of class
【新手指南】严重: Exception sending context initialized event to listener instance of class
384 0
【新手指南】严重: Exception sending context initialized event to listener instance of class
|
XML Java 数据库连接
【Error】:BeanCreationException: Error creating bean(Could not resolve resource location)
【Error】:BeanCreationException: Error creating bean(Could not resolve resource location)
310 0
【Error】:BeanCreationException: Error creating bean(Could not resolve resource location)
|
Java 应用服务中间件
Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
|
Java Apache Spring
Exception sending context initialized event to listener instance of class
详细错误信息如下: 严重: Exception sending context initialized event to listener instance of class com.auth.spring.
1199 0
why my cloudDatabaseconfig bean Initialization failed
why my cloudDatabaseconfig bean Initialization failed
why my cloudDatabaseconfig bean Initialization failed