启动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();
聚酯纤维被}
}
}