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. python 20 规范化目录

    目录 规范化目录 1. 划归固定的路径: 2. 划分文件 2.1 seetings 配置文件 2.2 common 公共组件文件 2.3 src 主文件 2.4 starts 项目启动文件 2.5 类 ...

  2. Python -二叉树 创建与遍历算法(很详细)

    树表示由边连接的节点.它是一个非线性的数据结构.它具有以下特性. 一个节点被标记为根节点. 除根节点之外的每个节点都与一个父节点关联. 每个节点可以有一个arbiatry编号的chid节点. 我们使用 ...

  3. Leetcode之回溯法专题-17. 电话号码的字母组合(Letter Combinations of a Phone Number)

    [Leetcode]17. 电话号码的字母组合(Letter Combinations of a Phone Number) 题目描述: 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组 ...

  4. 一文读懂HashMap

    推荐 转载:https://www.jianshu.com/p/ee0de4c99f87

  5. JMeter特点&性能测试工具选型的原则&模拟压力的原理

    1.JMeter自身的特点 1)开源.轻量级.更适合自动化和持续集成(100M左右,LoadRunner 4G左右) 2)学习难度大 3)资料少.全英文 2. 性能测试工具选型的原则 1)成本 a.工 ...

  6. CodeForces 809B Glad to see you!

    Glad to see you! 题解: 交互题一般都是需要用二分去完成. 在二分时候每次检查左边和右边哪边会和答案更近, 然后在更近的那段新区间去重复检查, 知道区间长度为1. 在检查的时候,可以使 ...

  7. codeforces 768 C. Jon Snow and his Favourite Number(思维+暴力)

    题目链接:http://codeforces.com/contest/768/problem/C 题意:给出n个数,k个操作,和一个x,每次操作先排序然后对奇数位数进行xor x操作,最后问k次操作后 ...

  8. AOE工程实践-NCNN组件

    作者:杨科 NCNN是腾讯开源的一个为手机端极致优化的高性能神经网络前向计算框架.在AOE开源工程里,我们提供了NCNN组件,下面我们以SqueezeNet物体识别这个Sample为例,来讲一讲NCN ...

  9. 洛谷 P1980【计数问题】 题解(2)

    还有一种办法,就是用stringstream函数将每一次的数全都转化成char一维数组样式的字符串,然后逐位扫一遍即可. (记得判断字符时将规定数字+48) //Stand up for the fa ...

  10. Day004_Linux基础命令之特殊符号与正则表达式通配符

    特殊符号: . 点 cd . 表示当前目录 ' '' 单引号,所见即所得 原封不动输出 " ""双引号,里面的特殊符号会被解析运行 `` ====$( ) 先运行() 里 ...