Spring 梳理 - javaConfig在App和webApp中的应用
- package com.dxz.demo.configuration;
- import org.springframework.context.annotation.Configuration;
- @Configuration
- public class TestConfiguration {
- public TestConfiguration() {
- System.out.println("TestConfiguration容器启动初始化。。。");
- }
- }
- APP
- 方法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
- public static void main(String[] args) {
- ApplicationContext ctx = new AnnotationConfigApplicationContext();
- ctx.register(AppContext.class)
- }
- public static void main(String[] args) {
- 方法1
- webApp
- 方法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>
- <web-app>
- 方法2
- 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[] { "/" };
- }
- }
- 方法1
Spring 梳理 - javaConfig在App和webApp中的应用的更多相关文章
- Spring 梳理 - JavaConfig、SPI、SCI、SpringSCI、WebApplicationInitializer、AbstractAnnotationConfigDispatcherServletInitializer、WebMvcConfigurationSupport
总结1: SCI:Servlet容器(Tomcat)提供的初始化Servlet容器本身的接口,可替换web.xml SpringSCI:SpringServletContainerInitialize ...
- Spring 梳理 - JavaConfig实战(spring MVC)-原创
目录结构 AppInitializer.java package com.jt; import org.springframework.web.servlet.support.AbstractAnno ...
- 利用spring boot创建java app
利用spring boot创建java app 背景 在使用spring框架开发的过程中,随着功能以及业务逻辑的日益复杂,应用伴随着大量的XML配置和复杂的bean依赖关系,特别是在使用mvc的时候各 ...
- 手机APP有三类:原生APP,WebAPP,HybridApp
搭建 AngularJS+Ionic+Cordova 开发环境并运行一个demo 目前的手机APP有三类:原生APP,WebAPP,HybridApp:HybridApp结合了前两类APP各自的优点, ...
- tomcat中session在两个webapp中实现共享
现在遇到一个需求就是要求完成简单的单点登录,通过在一个tomcat实例中放置两个webapps应用ROOT应用和CEO应用来完成在ROOT应用登录后,在CEO可以直接使用,而未在ROOT应用登录时,不 ...
- 从App业务逻辑中提炼API接口
2.1 从App业务逻辑中提炼API接口 业务逻辑思维导图 功能-业务逻辑思维导图 基本功能模块关系 功能模块接口UML(设计出API) 在设计稿标注API 编写API文档 2.2 设计API的要点 ...
- Spring 使用javaconfig配置
除了使用xml,spring提供javaconfig配置,下面是简单的例子: 1.声明接口 /** * */ package com.junge.demo.spring.service; /** * ...
- Spring 梳理 - filter、interceptor、aop实现与区别 -第二篇
spring mvc中的Interceptor可以理解为是Spring MVC框架对AOP的一种实现方式.一般简单的功能又是通用的,每个请求都要去处理的,比如判断token是否失效可以使用spring ...
- Spring 梳理-跨重定向请求传递数据-Flash
Spring MVC Flash Attribute 的讲解与使用示例 1. Spring MVC 3.1版本加了一个很有用的特性,Flash属性,它能解决一个长久以来缺少解决的问题,一个POST/R ...
随机推荐
- HTTP head请求
GET: 请求指定的页面信息,并返回实体主体. HEAD: 只请求页面的首部. POST: 请求服务器接受所指定的文档作为对所标识的URI的新的从属实体. PUT: 从客户端向服务器传送的数据取代指定 ...
- linux安装redis详细步骤(系统centos 6.4 )
1.安装redis 进入安装目录下载: cd /usr/local/redis wget http://download.redis.io/releases/redis-3.0.7.tar.gz 解 ...
- 技术改变生活| 免费看VIP视频,屏蔽广告,解锁新姿势!
说到这个,我就忍不住的要介绍一下今天的主角 Tampermonkey 了.Tampermonkey 是一款免费的浏览器扩展和最为流行的用户脚本管理器,它适用于Chrome, Microsoft Edg ...
- 超越Storm,SparkStreaming——Flink如何实现有状态的计算
流式计算分为无状态和有状态两种情况.无状态计算观察每个独立的事件,Storm就是无状态的计算框架,每一条消息来了以后和前后都没有关系,一条是一条.比如我们接收电力系统传感器的数据,当电压超过240v就 ...
- lightoj 1140 - How Many Zeroes?(数位dp)
Jimmy writes down the decimal representations of all natural numbers between and including m and n, ...
- codeforces 799 D. Field expansion(dfs+思维剪枝)
题目链接:http://codeforces.com/contest/799/problem/D 题意:给出h*w的矩阵,要求经过操作使得h*w的矩阵能够放下a*b的矩阵,操作为:将长或者宽*z[i] ...
- Play on Words UVA - 10129
题目: Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has ...
- uiautomator2 实现App九宫格解锁
App九宫格解锁 之前在testerhome社区看见codeskyblue大佬写过一种方法,但是这种办法存在一个弊端,那就是多个点的坐标是写死的,也就是说要是换了部手机,九宫格解锁就行不通了,于是就想 ...
- js中的this介绍
今天跟大家一起简单的来了解一下js中一个有趣的东西,this. 在js中我们用面向对象的思想去编写的时候,各个模块之间的变量就不那么容易获取的到了,当然也可以通过闭包的方式拿到其他函数的变量,如果说每 ...
- 【Spring】 AOP Base
1. AOP概述 2. AOP的术语: 3. AOP底层原理 4. Spring 中的AOP 4.1 概述 4.2 分类 4.3 Spring的传统AOP 针对所有方法的增强:(不带有切点的切面) 带 ...