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

然后就成功解决了。

目录
相关文章
|
8天前
|
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.
14 0
|
10月前
|
Java 数据库连接 数据库
【Java异常】Failed to determine a suitable driver class
【Java异常】Failed to determine a suitable driver class
239 0
|
Java 数据库连接 数据库
Unable to evaluate the expression Method threw ‘org.hibernate.LazyInitializationException‘ exceptio
Unable to evaluate the expression Method threw ‘org.hibernate.LazyInitializationException‘ exceptio
|
XML Java 数据格式
Exception encountered during context initialization - cancelling refresh attempt
Exception encountered during context initialization - cancelling refresh attempt:
287 0
|
Java Spring
【新手指南】严重: Exception sending context initialized event to listener instance of class
【新手指南】严重: Exception sending context initialized event to listener instance of class
422 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)
338 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.
Gradle sync failed: Unsupported method: NativeArtifact.getSourceFolders().
Gradle sync failed: Unsupported method: NativeArtifact.getSourceFolders().
90 0
why my cloudDatabaseconfig bean Initialization failed
why my cloudDatabaseconfig bean Initialization failed
why my cloudDatabaseconfig bean Initialization failed