spring-注解

1.在web.xml配置启动的listener

    <listener>
        <listener-class>com.my.core.web.listener.SpringLoaderListener</listener-class>
    </listener>

启动容器的代码

public class SpringLoaderListener extends ContextLoaderListener
{
  public void contextInitialized(ServletContextEvent event)
  {
    super.contextInitialized(event);
    ServletContext context = event.getServletContext();
//设置容器为Servlet容器
    ContextUtil.setServletContext(context);  
/*WebApplicationContextUtils是org.springframework.web.context.support. 
 WebApplicationContextUtils中的类*/
    ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
    ContextUtil.setContext(ctx);
  }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 文章概要 起因和概述 常用注解解析控制反转IOC,容器的作用依赖注入DI,获取对象的作用面象切面AOP声明式事务T...
    4ea0af17fd67阅读 2,278评论 1 3
  • 一、Java Web注解开发 使用Java Web 注解开发可以不用不用任何xml配置文件来开发Java Web。...
    有点胖的小乐乐阅读 6,838评论 1 21
  • Spring目前的趋势是使用注解结合Java代码而不是配置来定义行为、属性、功能、规则和扩展点,因此梳理注解也是梳...
    墨雨轩夏阅读 1,181评论 0 30
  • 逐渐的,在Spring的开发过程中,注解的使用越来越频繁,之前一直不喜欢注解,因为个人觉得可读性不好,但是正是这个...
    帅可儿妞阅读 1,188评论 0 4
  • 一、Annotation装配(@Configuration)1,替代Xml装配在resource/META-INF...
    西西_20f6阅读 666评论 0 0