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

然后就成功解决了。

目录
相关文章
|
Java Maven Android开发
成功解决FATAL ERROR in native method: JDWP on getting class status, jvmtiError=JVMTI_ERROR_WRONG_PHASE
成功解决FATAL ERROR in native method: JDWP on getting class status, jvmtiError=JVMTI_ERROR_WRONG_PHASE
|
8月前
|
机器学习/深度学习 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
247 0
|
Java 数据库连接 数据库
【Java异常】Failed to determine a suitable driver class
【Java异常】Failed to determine a suitable driver class
492 0
|
XML Java 数据格式
Exception encountered during context initialization - cancelling refresh attempt
Exception encountered during context initialization - cancelling refresh attempt:
349 0
|
XML Java 数据库连接
【Error】:BeanCreationException: Error creating bean(Could not resolve resource location)
【Error】:BeanCreationException: Error creating bean(Could not resolve resource location)
387 0
【Error】:BeanCreationException: Error creating bean(Could not resolve resource location)
error: exception handling disabled, use -fexceptions to enable
error: exception handling disabled, use -fexceptions to enable
75 0
Gradle sync failed: Unsupported method: NativeArtifact.getSourceFolders().
Gradle sync failed: Unsupported method: NativeArtifact.getSourceFolders().
110 0

热门文章

最新文章

下一篇
开通oss服务