解决报错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类型。

然后就成功解决了。

目录
相关文章
|
4月前
|
Java Maven
Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
75 0
|
7月前
|
JavaScript 安全 网络安全
Node: opensslErrorStack: [ ‘error:03000086:digital envelope routines::initialization error‘ ]异常处理
Node: opensslErrorStack: [ ‘error:03000086:digital envelope routines::initialization error‘ ]异常处理
3123 1
|
6月前
|
Java Spring
【已解决】Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception .lang.NullPointerEx
【已解决】Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception .lang.NullPointerEx
89 0
|
Java Spring
BeanCreationException: Error creating bean with name ‘configurationPropertiesBeans‘ defined in class
BeanCreationException: Error creating bean with name ‘configurationPropertiesBeans‘ defined in class
249 0
|
XML Java 数据格式
Exception encountered during context initialization - cancelling refresh attempt
Exception encountered during context initialization - cancelling refresh attempt:
342 0
|
XML Java 数据库连接
【Error】:BeanCreationException: Error creating bean(Could not resolve resource location)
【Error】:BeanCreationException: Error creating bean(Could not resolve resource location)
376 0
【Error】:BeanCreationException: Error creating bean(Could not resolve resource location)
|
Java 数据库连接 网络安全
Error creating bean with name ‘attrAttrgroupRelationController‘
Error creating bean with name ‘attrAttrgroupRelationController‘
Error creating bean with name ‘attrAttrgroupRelationController‘
|
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.