这个其实很简单
1.在spring-mvc中配置:
<bean class="com.company.listener.StartUpListener"/>
2.新建StartUpListener类
@Service
public class StartUpListener implements ApplicationListener<ContextRefreshedEvent> {
@Autowired
public UserMapper userMapper;
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
if(event.getApplicationContext().getParent() != null){
}
}
}
ps:网上说会执行两次,需要判断event.getApplicationContext().getParent()为空,但是我测试的时候,发现只执行一次,并且是ServletContext,不为空,所以我加了不为空的判断。
下面是静态资源的配置
1.spring-mvc下配置
<mvc:resources mapping="/static/**" location="/WEB-INF/static/"/>
2.在/WEB-INF/static/下放任意文件,重新部署项目,都能通过../static/文件名 的地址访问到该文件