1. package com.dxz.demo.configuration;
    
    import org.springframework.context.annotation.Configuration;
    
    @Configuration
    public class TestConfiguration {
    public TestConfiguration() {
    System.out.println("TestConfiguration容器启动初始化。。。");
    }
    }
  2. APP
    1. 方法1
      1. package com.dxz.demo.configuration;
        
        import org.springframework.context.ApplicationContext;
        import org.springframework.context.annotation.AnnotationConfigApplicationContext; public class TestMain {
        public static void main(String[] args) { // @Configuration注解的spring容器加载方式,用AnnotationConfigApplicationContext替换ClassPathXmlApplicationContext
        ApplicationContext context = new AnnotationConfigApplicationContext(TestConfiguration.class); // 如果加载spring-context.xml文件:
        // ApplicationContext context = new
        // ClassPathXmlApplicationContext("spring-context.xml");
        }
        } public static void main(String[] args) { // @Configuration注解的spring容器加载方式,用AnnotationConfigApplicationContext替换ClassPathXmlApplicationContext
        ApplicationContext context = new AnnotationConfigApplicationContext(TestConfiguration.class); //获取bean
        TestBean tb = (TestBean) context.getBean("testBean");
        tb.sayHello();
        }
    2. 方法2
      1. public static void main(String[] args) {
        ApplicationContext ctx = new AnnotationConfigApplicationContext();
        ctx.register(AppContext.class)
        }
  3. webApp
    1. 方法1
      1. <web-app>
        <context-param>
        <param-name>contextClass</param-name>
        <param-value>
        org.springframework.web.context.
        support.AnnotationConfigWebApplicationContext
        </param-value>
        </context-param>
        <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
        demo.AppContext
        </param-value>
        </context-param>
        <listener>
        <listener-class>
        org.springframework.web.context.ContextLoaderListener
        </listener-class>
        </listener>
        <servlet>
        <servlet-name>sampleServlet</servlet-name>
        <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
        <param-name>contextClass</param-name>
        <param-value>
        org.springframework.web.context.
        support.AnnotationConfigWebApplicationContext
        </param-value>
        </init-param>
        </servlet>
        </web-app>
    2. 方法2
      1. package com.jt;
        
        import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
        
        public class AppInitializer   extends AbstractAnnotationConfigDispatcherServletInitializer{
        @Override
        protected Class<?>[] getRootConfigClasses() {
        return new Class<?>[] { RootConfig.class };
        } @Override
        protected Class<?>[] getServletConfigClasses() {
        return new Class<?>[] { WebConfig.class };
        } @Override
        protected String[] getServletMappings() {
        return new String[] { "/" };
        } }

Spring 梳理 - javaConfig在App和webApp中的应用的更多相关文章

  1. Spring 梳理 - JavaConfig、SPI、SCI、SpringSCI、WebApplicationInitializer、AbstractAnnotationConfigDispatcherServletInitializer、WebMvcConfigurationSupport

    总结1: SCI:Servlet容器(Tomcat)提供的初始化Servlet容器本身的接口,可替换web.xml SpringSCI:SpringServletContainerInitialize ...

  2. Spring 梳理 - JavaConfig实战(spring MVC)-原创

    目录结构 AppInitializer.java package com.jt; import org.springframework.web.servlet.support.AbstractAnno ...

  3. 利用spring boot创建java app

    利用spring boot创建java app 背景 在使用spring框架开发的过程中,随着功能以及业务逻辑的日益复杂,应用伴随着大量的XML配置和复杂的bean依赖关系,特别是在使用mvc的时候各 ...

  4. 手机APP有三类:原生APP,WebAPP,HybridApp

    搭建 AngularJS+Ionic+Cordova 开发环境并运行一个demo 目前的手机APP有三类:原生APP,WebAPP,HybridApp:HybridApp结合了前两类APP各自的优点, ...

  5. tomcat中session在两个webapp中实现共享

    现在遇到一个需求就是要求完成简单的单点登录,通过在一个tomcat实例中放置两个webapps应用ROOT应用和CEO应用来完成在ROOT应用登录后,在CEO可以直接使用,而未在ROOT应用登录时,不 ...

  6. 从App业务逻辑中提炼API接口

    2.1 从App业务逻辑中提炼API接口 业务逻辑思维导图 功能-业务逻辑思维导图 基本功能模块关系 功能模块接口UML(设计出API) 在设计稿标注API 编写API文档 2.2 设计API的要点 ...

  7. Spring 使用javaconfig配置

    除了使用xml,spring提供javaconfig配置,下面是简单的例子: 1.声明接口 /** * */ package com.junge.demo.spring.service; /** * ...

  8. Spring 梳理 - filter、interceptor、aop实现与区别 -第二篇

    spring mvc中的Interceptor可以理解为是Spring MVC框架对AOP的一种实现方式.一般简单的功能又是通用的,每个请求都要去处理的,比如判断token是否失效可以使用spring ...

  9. Spring 梳理-跨重定向请求传递数据-Flash

    Spring MVC Flash Attribute 的讲解与使用示例 1. Spring MVC 3.1版本加了一个很有用的特性,Flash属性,它能解决一个长久以来缺少解决的问题,一个POST/R ...

随机推荐

  1. 解决ionic 中 $ionicHistory.goBack()无法返回

    这种解决方法目前只适合用了 <ion-side-menus>这一组件的<ion-view> 解决方法: 在<ion-view>下一级中包一个div,如下图: 搞了几 ...

  2. 礼盒抖动动画(CocosCreator)

    推荐阅读:  我的CSDN  我的博客园  QQ群:704621321       这个月还有一天了,别问我为什么是一天,996,懂吗?项目是做不完了,策划又加新功能,又不能安静的改bug了.又是动画 ...

  3. Mysql根据出生日期计算年龄五种方法比较

    方法一 SELECT DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(birthday)), '%Y')+0 AS age 方法一缺陷,就是当日期为未来日期时 ...

  4. [2018CCPC吉林赛区(重现赛)- 感谢北华大学] 补题记录 躁起来

    1007 High Priestess 埃及分数 1008 Lovers 线段树维护取膜意义下的区间s和. 每个区间保存前缀lazy和后缀lazy. #include <iostream> ...

  5. Luogu-P1027 Car的旅行路线 已知三点确定矩形 + 最短路

    传送门:https://www.luogu.org/problemnew/show/P1027 题意: 图中有n个城市,每个城市有4个机场在矩形的四个顶点上.一个城市间的机场可以通过高铁通达,不同城市 ...

  6. P1603 斯诺登的密码-字符串加法的妙用

    传送门:https://www.luogu.org/problemnew/show/P1603 题意: 首先在给定的字符串中,找出特定的单词,把它转化成特定的数字, 然后在这些数字中,找出排列结果最小 ...

  7. 杭电多校第二场 1005 hack it

    题意: 构造一个n*n 的 01 矩阵, 0 < n < 2001,  矩阵需要满足没有一个子矩阵的4个角都是1,并且矩阵内1的个数至少有85000个. 题解:数论构造题 参考From 代 ...

  8. codeforce 505 D. Mr. Kitayuta's Technology(tarjan+并查集)

    题目链接:http://codeforces.com/contest/505/problem/D 题解:先用tarjan缩点然后再用并查集注意下面这种情况 ‘ 这种情况只需要构成一个大环就行了,也就是 ...

  9. mariadb+haproxy实现负载均衡(一)

    根据实际情况,数据生产无论是量还是使用地方都在稳步增加,单一服务器的稳定性也越来越受到关注,所以想提前做好技术准备. 因为之前就安装好了数据库,现在只讨论haproxy的安装及相关使用. haprox ...

  10. Dockfile 生成docker镜像文件大小的比较

    下面就是我针对docker file同一个文件,按照layer层的个数的多少,分别构建了两个镜像的jenkins-master.两者大小相差300MB. <1> layer层数太多,没有将 ...