当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
三子棋讲解(C语言)
数字孪生将成为进入“元宇宙”一项重要的途径
If the account number or password is entered incorrectly for many times, the account will be banned.
find、filter、map的区别
Error: Cannot find module 'D:\Application\nodejs\node_modules\npm\bin\npm-cli.js'
Kubernetes certificate validity period modification
2021 Mianjing - Embrace Change
[JVM Loading]---Class Loading Mechanism
Flink sink redis writes to Redis
【数据库学习】Redis 解析器&&单线程&&模型
leetcode-每日一题745. 前缀和后缀搜索(哈希和字典树)
数字取证autopsy工具用法
12 【网页布局总结 元素的显示与隐藏】
了解SSRF,这一篇就足够了
利用phpstudy搭建DVWA
gin框架学习-GORM框架进阶之CRUD接口(数据库增删改查操作)
实验8 DNS解析
DeFi 项目中的治理Token
uni-app进阶之认证【day12】
C语言文件读、写、定位函数