当前位置:网站首页>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
边栏推荐
猜你喜欢

What is the difference between NFT and digital collection?
uni-app进阶之认证【day12】

什么是 GameFi?

gin框架学习-JWT认证

【windows】--- SQL Server 2008 超详细安装教程

【云原生】微服务Nacos的简单介绍与使用

Year-end summary - the years are quiet~

mac10.14中安装mysqldb

Error: Cannot find module ‘D:\Application\nodejs\node_modules\npm\bin\npm-cli.js‘

mysql password modification method in Linux (pro-test available)
随机推荐
NFT与数字藏品到底有何区别?
字符串的新增方法
第7章 网络层第1次练习题答案(第三版)
mac10.14中安装mysqldb
leetcode-每日一题873. 最长的斐波那契子序列的长度(哈希和二分)
leetcode-每日一题565. 数组嵌套(标记图和并查集)
On the side of Ali, tell me what are the application scenarios of message middleware you know?
Build vulhub vulnerability shooting range on kali
【数据库学习】Redis 解析器&&单线程&&模型
可以“繁殖”的程序
为什么redis是单线程还那么快?
MySQL-如何分库分表?一看就懂
工件SSMwar exploded 部署工件时出错。请参阅服务器日志了解详细信息
08 【生命周期 组件】
What is the difference between NFT and digital collection?
(Crypto必备干货)详细分析目前NFT的几大交易市场
【ubuntu20.04安装MySQL以及MySQL-workbench可视化工具】
DeFi 项目中的治理Token
Redis:安装使用
PHP中abstract(抽象)、final(最终)和static(静态)原理与用法