启动SSM项目时自动执行方法

更新时间:2023-06-21 02:39:45 阅读: 评论:0

启动SSM项⽬时⾃动执⾏⽅法
⼀定要扫描这个⼯具类,否则是不会⽣效的,因为有注解
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="www.springframework/schema/beans"
水彩画图片大全xsi="www.w3/2001/XMLSchema-instance"
context="www.springframework/schema/context"
mvc="www.springframework/schema/mvc"
schemaLocation="www.springframework/schema/beans www.springframework/schema/beans/spring-beans.xsd www.spri ngframework/schema/context www.springframework/schema/context/spring-context.xsd www.springframework/schema/mvc w ww.springframework/schema/mvc/spring-mvc.xsd">
<!--启动并扫描rvice的注解,否则controller中的autowired⽆效-->
<annotation-driven/>
<!--扫描rvice-->
<component-scan ba-package="com.xjj.rvice"/>
<!--扫描util-->
<component-scan ba-package="com.xjj.util"/>
<!--引⼊其他的配置⽂件-->
<import resource="classpath:spring/Spring-*.xml"/>
</beans>
package com.xjj.util;
import ller.InitController;
import t.ApplicationListener;
减肥早餐import t.event.ContextRefreshedEvent;
初中历史课件import t.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;
四年级满分作文@Service
public class InitListener implements ApplicationListener<ContextRefreshedEvent>{
public final static String ROOT="Root WebApplicationContext";
/**
* 启动项⽬时会⾃动调⽤这个⽅法
夜壶* @param contextRefreshedEvent
*/
@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent){
if(ROOT.ApplicationContext().getDisplayName())){
//获取容器,读取核⼼配置类
ClassPathXmlApplicationContext classPathXmlApplicationContext=new ClassPathXmlApplicationContext("l");
//获取你要操作的类和类的⽅法
怎么学做蛋糕//1、获得initController的bean
母兮鞠我InitController initController=(InitController) Bean("initController");
//2、执⾏初始化的⽅法
initController.init();
聚酯纤维被}
}
}

本文发布于:2023-06-21 02:39:45,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1002809.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:扫描   读取   获取
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图