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. MSIL实用指南-this的生成

    C#关键字是非静态方法体内部,用Ldarg_0指代this例子ilGenerator.Emit(OpCodes.Ldarg_0);

  2. cogs 1377. [NOI2011] NOI嘉年华 (dp

    题意:给你n个活动的起止时间,要你从中选一些活动在2个会场安排(不能有两个活动在两个会场同时进行),使活动较少的会场活动数最大,以及在某个活动必须选择的前提下,求该答案. 思路:由于n很小,时间很大, ...

  3. CF1036C Classy Numbers dfs+二分

    Classy Numbers time limit per test 3 seconds memory limit per test 256 megabytes input standard inpu ...

  4. CodeForces 1084D The Fair Nut and the Best Path

    The Fair Nut and the Best Path 题意:求路径上的 点权和 - 边权和 最大, 然后不能存在某个点为负数. 题解: dfs一遍, 求所有儿子走到这个点的最大值和次大值. 我 ...

  5. Codeforces Technocup 2017 - Elimination Round 2 D. Sea Battle(贪心)

    题目链接 http://codeforces.com/contest/729/problem/D 题意:给你一个1*n的区域有a艘船,每艘船宽b,已经开了k枪都没打到,问你最少再开几枪至少能打到一艘船 ...

  6. php preg_match pcre回溯绕过

    原理需要知识:正则NFA回溯原理,php的pcre.backtrack_limit设置. 正则NFA回溯原理正则表达式是一个可以被"有限状态自动机"接受的语言类."有限状 ...

  7. Netty源码分析 (六)----- 客户端连接接入accept过程

    通读本文,你会了解到1.netty如何接受新的请求2.netty如何给新请求分配reactor线程3.netty如何给每个新连接增加ChannelHandler netty中的reactor线程 ne ...

  8. 9道JavaScript字符串类面试题

    本文来源于笔者的开源项目前端面试与进阶指南 点击关注本公众号获取文档最新更新,并可以领取配套于本指南的 <前端面试手册> 以及最标准的简历模板. 解析 URL Params 为对象 let ...

  9. 如何将 JavaScript 代码添加到网页中,以及 <script> 标签的属性

    Hello, world! 本教程的这一部分内容是关于 JavaScript 语言本身的. 但是,我们需要一个工作环境来运行我们的脚本,由于本教程是在线的,所以浏览器是一个不错的选择.我们会尽可能少地 ...

  10. 使用Quarkus在Openshift上构建微服务的快速指南

    在我的博客上,您有机会阅读了许多关于使用Spring Boot或Micronaut之类框架构建微服务的文章.这里将介绍另一个非常有趣的框架专门用于微服务体系结构,它越来越受到大家的关注– Quarku ...