“java.lang.IllegalStateException: No ConfigurableListableBeanFactory set“,缺少配置

一、错误分析

做品优购项目的运营商安全登录时,运行项目后,浏览器访问模板页,模板页的表格无法正常显示,报错信息如下:

java 复制代码
SEVERE: StandardWrapper.Throwable
java.lang.IllegalStateException: No ConfigurableListableBeanFactory set
        at org.springframework.util.Assert.state(Assert.java:73)
        at org.springframework.context.event.EventListenerMethodProcessor.afterSingletonsInstantiated(EventListenerMethodProcessor.java
:102)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.jav
a:862)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.ja
va:877)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
        at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:701)
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:667)
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:715)
        at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:590)
        at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:529)
        at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:169)
        at javax.servlet.GenericServlet.init(GenericServlet.java:160)
        at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
        at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:865)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

访问页面失败:

提取关键信息:

java 复制代码
java.lang.IllegalStateException: No ConfigurableListableBeanFactory set

根据上述错误,可能是因为缺少了ConfigurableListableBeanFactory的配置,定位到springmvc.xml文件

二、代码修改

springmvc.xml文件修改前:

XML 复制代码
<?xml version="1.0" encoding="UTF-8"?>
	<beans xmlns="http://www.springframework.org/schema/beans"
		   xmlns:context="http://www.springframework.org/schema/context"
		   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		   xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
		   xmlns:mvc="http://www.springframework.org/schema/mvc"
		   xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
              http://www.springframework.org/schema/mvc
              http://www.springframework.org/schema/mvc/spring-mvc.xsd
              http://code.alibabatech.com/schema/dubbo
              http://code.alibabatech.com/schema/dubbo/dubbo.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context-4.0.xsd">

	<context:property-placeholder location="classpath:config/application.properties" />
	
	<mvc:annotation-driven>
	  <mvc:message-converters register-defaults="true">
	    <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">  
	      <property name="supportedMediaTypes" value="application/json"/>
	      <property name="features">
	        <array>
	          <value>WriteMapNullValue</value>
	          <value>WriteDateUseDateFormat</value>
	        </array>
	      </property>
	    </bean>
	  </mvc:message-converters>  
	</mvc:annotation-driven>

	<!-- 引用dubbo 服务 -->
	<dubbo:application name="pinyougou-manager-web" />
	<dubbo:registry address="zookeeper://192.168.25.139:2181"/>
	<dubbo:annotation package="com.pinyougou.manager.controller" />

</beans>

springmvc.xml文件修改后:

XML 复制代码
<beans xmlns="http://www.springframework.org/schema/beans"
	   xmlns:context="http://www.springframework.org/schema/context"
	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
	   xmlns:mvc="http://www.springframework.org/schema/mvc"
	   xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
          http://www.springframework.org/schema/mvc
          http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://code.alibabatech.com/schema/dubbo
          http://code.alibabatech.com/schema/dubbo/dubbo.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-4.0.xsd">

	<context:property-placeholder location="classpath:config/application.properties" />

	<mvc:annotation-driven>
		<mvc:message-converters register-defaults="true">
			<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
				<property name="supportedMediaTypes" value="application/json"/>
				<property name="features">
					<array>
						<value>WriteMapNullValue</value>
						<value>WriteDateUseDateFormat</value>
					</array>
				</property>
			</bean>
		</mvc:message-converters>
	</mvc:annotation-driven>

	<!-- 引用dubbo 服务 -->
	<dubbo:application name="pinyougou-manager-web" />
	<dubbo:registry address="zookeeper://192.168.25.139:2181"/>
	<dubbo:annotation package="com.pinyougou.manager.controller" />

	<context:annotation-config/>
</beans>

在代码中添加了<context:annotation-config/>,这样可以确保ConfigurableListableBeanFactory正确配置

再次运行代码,正常访问页面

三、 怎么知道代码改哪里

目前在用chatgpt网站:AIGC+ (aigcplus.io)

把错误信息和要修改的代码贴上,直接问它,"请根据上述错误修改下列代码",即可得到较为正确的修改方向

相关推荐
汤米粥3 分钟前
小皮PHP连接数据库提示could not find driver
开发语言·php
冰淇淋烤布蕾6 分钟前
EasyExcel使用
java·开发语言·excel
拾荒的小海螺13 分钟前
JAVA:探索 EasyExcel 的技术指南
java·开发语言
Jakarta EE29 分钟前
正确使用primefaces的process和update
java·primefaces·jakarta ee
马剑威(威哥爱编程)37 分钟前
哇喔!20种单例模式的实现与变异总结
java·开发语言·单例模式
白-胖-子1 小时前
【蓝桥等考C++真题】蓝桥杯等级考试C++组第13级L13真题原题(含答案)-统计数字
开发语言·c++·算法·蓝桥杯·等考·13级
好睡凯1 小时前
c++写一个死锁并且自己解锁
开发语言·c++·算法
java—大象1 小时前
基于java+springboot+layui的流浪动物交流信息平台设计实现
java·开发语言·spring boot·layui·课程设计
yyqzjw1 小时前
【qt】控件篇(Enable|geometry)
开发语言·qt
csdn_kike1 小时前
QT Unknown module(s) in QT 以及maintenance tool的更详细用法(qt6.6.0)
开发语言·qt