当前位置:网站首页>Artifact SSMwar exploded Error deploying artifact.See server log for details
Artifact SSMwar exploded Error deploying artifact.See server log for details
2022-07-31 05:53:00 【m0_67391401】
Add a Listener to web.xml today and an exception occurred
The artifact deployment failed when the Tomcat server started

Check the log to see that the bean that references the dao layer is not injected:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ProductTypeService' available
At this time, it is necessary to check whether the relevant bean injection is completed. When looking at the code, it is found that a bean injection is indeed missing:

Bean injection was added manually:

I thought it would be recognized at this time, but surprisingly, the same error is still reported!
Think about it carefully and check the code of my listener. The listener implements the ServletContextListener interface and is a global listener, that is, it will take effect as soon as the project is started, so I added an output message, which is "Enter the listener."
import com.konan.pojo.ProductType;import com.konan.service.ProductTypeService;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import javax.servlet.ServletContextEvent;import javax.servlet.ServletContextListener;import java.util.List;public class ProductTypeListener implements ServletContextListener {@Overridepublic void contextInitialized(ServletContextEvent sce) {System.out.println("Enter listener");ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext_*.xml");ProductTypeService productTypeService = (ProductTypeService) context.getBean("ProductTypeService");List allType = productTypeService.getAllType();System.out.println(allType);sce.getServletContext().setAttribute("typeList",allType);}@Overridepublic void contextDestroyed(ServletContextEvent sce) {}} Restart the viewing console:

You can see that the listener takes effect after the artifact is deployed, but the artifact has not yet been deployed!
The same error was reported later
Why is the injected bean ProductTypeService not recognized at this time?Obviously it has been injected!
What the listener needs to get is the bean of the ProductTypeService business layer, which is the upper interface of ProductTypeServiceImpl.Due to the early effective time of the listener, the reference name of the bean we automatically injected has not yet taken effect (in fact, the bean has been injected, but the listener cannot recognize it at this time, and the initial letter of the lowercase class name is also useless).It's time to use a custom bean name!
Add @Service("bean")
- Custom bean name, you can specify it like @Service("aaaaa"), this bean is singleton by default
- The default name when not specified is the class name (initial lowercase),
Finally modified to the following form to run normally!

Let me introduce myself first. The editor graduated from Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Ali in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a "full set of learning materials for java development" for everyone. The original intention is also very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials
边栏推荐
- Build vulhub vulnerability shooting range on kali
- 闭包(三)----执行环境
- GUCCI, LV and other luxury giant universe how to layout yuan, other brands should keep up with?
- mysql启动报错The server quit without updating PID file几种解决办法
- 什么是 GameFi?
- 【云原生】SQL(及存储过程)跑得太慢怎么办?
- The process and specific code of sending SMS verification code using flask framework
- (Crypto essential dry goods) Detailed analysis of the current NFT trading markets
- C language tutorial (3) - if and loop
- 11 【组件通信】
猜你喜欢

什么是EVM兼容链?

数字取证autopsy工具用法

feign调用不通问题,JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r

【云原生】SQL(及存储过程)跑得太慢怎么办?

leetcode-每日一题1217. 玩筹码(贪心+位运算)

Fragmented NFT (Fractional NFT)
![[Elastic-Job source code analysis] - job listener](/img/99/5e047b1aa83aad7d7f17b4eec606e6.png)
[Elastic-Job source code analysis] - job listener

DeFi 项目中的治理Token

“档次法”——用于物品体积分布不均匀的01背包问题的求解方法

leetcode-每日一题735. 行星碰撞(栈模拟)
随机推荐
The MySQL database in Alibaba Cloud was attacked, and the data was finally recovered
为什么redis是单线程还那么快?
win11中利用IIS10搭建asp网站
5 methods of MySQL paging query
【C语言3个基本结构详解——顺序、选择、循环】
Install mysqldb in mac10.14
【Elastic-Job源码分析】——作业监听器
16 【打包上线 图片懒加载】
碎片化NFT(Fractional NFT)
NFT:数字所有权的核心
【swagger关闭】生产环境关闭swagger方法
代码执行漏洞
leetcode-每日一题1252. 奇数值单元格的数目(模拟优化)
03 【数据代理 事件处理】
常见JVM面试题及答案整理
GUCCI、LV等奢侈品巨头如何布局元宇宙的,其他品牌应该跟上吗?
[Elastic-Job source code analysis] - job listener
vulhub靶场学习日记SickOs1.2
永恒之蓝漏洞复现
详解扫雷游戏(C语言)