在apring-servlet.xml中配置
//上下文加载的作用:
spring项目中 通过自定义applicationContext工具类获取到applicationContext上下文对象
spring项目在服务器启动的时候 spring容器中就已经被创建好了各种对象,在我们需要使用的时候可以进行调用.
测试类testController, 测试上下文加载
SysAclModuleMapper moduleMapper = ApplicationContextHelper.popBean(SysAclModuleMapper.class);
SysAclModule module = moduleMapper.selectByPrimaryKey(2);
log.info(JsonMapper.obj2String(module));
效果:获取到 SysAclModuleMapper这个类, 接着获取到其中 根据id查询的方法selectByPrimaryKey
写工具类ApplicationContextHelper
package com.mmall.common;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component(“applicationContextHelper”)
public class ApplicationContextHelper implements ApplicationContextAware {
private static Appl