博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
4. Spring 4.2.3前瞻-使用@Order调整配置类加载顺序
阅读量:4119 次
发布时间:2019-05-25

本文共 1389 字,大约阅读时间需要 4 分钟。

4.1 @Order

  • Spring 4.2.3 利用@Order控制配置类的加载顺序

4.2 演示

  • 两个演示bean
package com.wisely.spring4_2.3.order;public class Demo1Service {}
package com.wisely.spring4_2.3.order;public class Demo2Service {}
两个配置类,注意@Order配置加载的顺序 
package com.wisely.spring4_2.3.order;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.core.annotation.Order;@Configuration@Order(2)public class Demo1Config { @Bean public Demo1Service demo1Service(){ System.out.println("demo1config 加载了"); return new Demo1Service(); }}
package com.wisely.spring4_2.3.order;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.core.annotation.Order;@Configuration@Order(1)public class Demo2Config { @Bean public Demo2Service demo2Service(){ System.out.println("demo2config 加载了"); return new Demo2Service(); }}
运行
package com.wisely.spring4_2.3.order;import org.springframework.context.annotation.AnnotationConfigApplicationContext;public class Main { public static void main(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext("com.wisely.spring4_2.order"); }}
输出结果
demo2config 加载了demo1config 加载了
读者可自己调整顺序在运行

转载地址:http://rjcpi.baihongyu.com/

你可能感兴趣的文章
linux shell 编程(四)
查看>>
php中的$_REQUEST、$_GET、$_POST
查看>>
http协议中的头部字段:Transfer-Encoding
查看>>
php主机字节序和网络字节序
查看>>
linux 查看CPU个数
查看>>
php中base64_encode base64_decode加密解密函数
查看>>
php sha1 hmac
查看>>
php中和mysql数据库相关函数
查看>>
linux curl命令详解
查看>>
php curl详解
查看>>
php socket编程
查看>>
linux /etc/resolv.conf /etc/hosts配置文件详解
查看>>
php配置文件详解
查看>>
nginx 代理 proxy_pass /etc/hosts
查看>>
nginx最大并发连接数的思考:worker_processes、worker_connections、worker_rlimit_nofile
查看>>
nginx配置详解
查看>>
linux 进程占用内存详解
查看>>
显示器系列1--常见参数详解
查看>>
linux cpu显示信息
查看>>
显示器系列1-我常用设备的分辨率等
查看>>