当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
1D, 2D, 3D convolution operations in pytorch
MySql创建数据表
PHP中abstract(抽象)、final(最终)和static(静态)原理与用法
变量的解构赋值
Kubernetes certificate validity period modification
2021面经-拥抱变化
SQL注入中数据库的判断
Oracle数据库中的“limit”查询
小白学爬虫——爬虫入门
DeFi Token in the project management
详解扫雷游戏(C语言)
数字孪生将成为进入“元宇宙”一项重要的途径
对于输出点是时间戳的渗透测试方法(以Oracle数据库为例)
[Elastic-Job] Overview of Distributed Scheduling Tasks
[Ubuntu20.04 installs MySQL and MySQL-workbench visualization tool]
win11中利用IIS10搭建asp网站
【uiautomation】微信好友列表获取(存储到txt中)
【数据库学习】Redis 解析器&&单线程&&模型
Redis 事务学习有感
vulhub靶场学习日记hackme1