当前位置:网站首页>工件SSMwar exploded 部署工件时出错。请参阅服务器日志了解详细信息
工件SSMwar exploded 部署工件时出错。请参阅服务器日志了解详细信息
2022-08-01 23:46:00 【web18334137065】
今天往web.xml中添加一个Listener监听器就出现了异常
Tomcat服务器启动时工件部署失败
查看日志得知是没有注入引用dao层的bean:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘ProductTypeService’ available
这个时候就要检查自己相关的bean注入是否完成了,查看代码时发现的确是缺少了一个bean注入:
手动添加了bean注入:
以为这个时候就能识别到了吧,但出人意料的是依旧报相同的错误!
仔细想一下,查看我监听器的代码,监听器实现了ServletContextListener接口,是一个全局监听器,也就是项目刚启动是就会生效,于是我添加了一条输出信息,就是“进入监听器”
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 {
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println("进入监听器");
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext_*.xml");
ProductTypeService productTypeService = (ProductTypeService) context.getBean("ProductTypeService");
List<ProductType> allType = productTypeService.getAllType();
System.out.println(allType);
sce.getServletContext().setAttribute("typeList",allType);
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}
重启查看控制台:
可以看到监听器是在部署工件后就生效了,但是此时工件还没有部署好!
之后便报除了相同的错误
这时候为什么还识别不到 ProductTypeService 这个注入的bean呢?明明已经注入了呀!
监听器中要获得的是 ProductTypeService 业务层的这个bean,也就是ProductTypeServiceImpl的上层接口。由于监听器过早的生效时间导致我们自动注入的bean的引用名称还没有生效(实际上bean已经注入了,但是监听器此时识别不到,小写类名首字母也没有用),这时候就要用到自定义bean名称了!
添加@Service(“bean”)
- 自定义bean名称,可以@Service(“aaaaa”)这样来指定,这种bean默认是单例的
- 不指定时的默认名称是类名(头字母小写),
最终修改为如下形式即可正常运行!
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- Spark Sql之union
- yay 报错 response decoding failed: invalid character ‘<‘ looking for beginning of value;
- ICLR 2022 Best Paper: Partial Label Learning Based on Contrastive Disambiguation
- Convert LocalDateTime to Date type
- 在MySQL登录时出现Access denied for user ‘root‘@‘localhost‘ (using password YES) 拒绝访问问题解决
- @Resource和@Autowired的区别
- @Transactional 注解使用详解
- Flink Yarn Per Job - 提交流程一
- 问题解决方式了
- Loading configuration of Nacos configuration center
猜你喜欢
Flink Yarn Per Job - Yarn应用
Various Joins of Sql
Deep Learning Fundamentals - Numpy-based Recurrent Neural Network (RNN) implementation and backpropagation training
The Spark of Sql join on the and and where
Quartus uses tcl files to quickly configure pins
在CDH的hue上的oozie出现,提交 Coordinator My Schedule 时出错
Classical Literature Reading--DLO
Making a Simple 3D Renderer
[email protected]与
YOLO等目标检测模型的非极大值抑制NMS和评价指标(Acc, Precision, Recall, AP, mAP, RoI)、YOLOv5中[email protected]与
机器学习文本分类
随机推荐
架构基本概念和架构本质
程序员还差对象?new一个就行了
1个月写900多条用例,二线城市年薪33W+的测试经理能有多卷?
oozie startup error on cdh's hue, Cannot allocate containers as requested resource is greater than maximum allowed
CDH6 Hue to open a "ASCII" codec can 't encode characters
Calculate the midpoint between two points
邻接表与邻接矩阵
sys_kill系统调用
@Transactional注解在类上还是接口上使用,哪种方式更好?
数据机构---第五章树与二叉树---二叉树的概念---应用题
Access the selected node in the console
在MySQL登录时出现Access denied for user ‘root‘@‘localhost‘ (using password YES) 拒绝访问问题解决
Architecture basic concept and nature of architecture
Additional Features for Scripting
一款简洁的文件传输工具
Flink学习第五天——Flink可视化控制台依赖配置和界面介绍
Bean的生命周期
numpy.hstack
在linux下MySQL的常用操作命令
Department project source code sharing