当前位置: 首页 > news >正文

广西建设职业技术学院贫困生网站自考本科含金量高吗

广西建设职业技术学院贫困生网站,自考本科含金量高吗,用.net做网站,怎么把wordpress的登录框放在首页目录 一、简介二、List 注入使用示例2.1 测试接口类2.2 测试接口实现类12.3 测试接口实现类22.4 启动类#xff08;测试#xff09;2.5 测试结果场景一#xff1a;场景二#xff1a; 三、CommandLineRunner 使用示例3.1 接口实现类13.2 接口实现类23.3 测试结果场景一… 目录 一、简介二、List 注入使用示例2.1 测试接口类2.2 测试接口实现类12.3 测试接口实现类22.4 启动类测试2.5 测试结果场景一场景二 三、CommandLineRunner 使用示例3.1 接口实现类13.2 接口实现类23.3 测试结果场景一场景二 四、Order失效场景4.1 失效代码示例4.2 执行结果4.3 失效场景补救 五、Order、Priority底层原理5.1 平平无奇的启动类5.2 神奇的 run() 方法5.3 开始排序的 callRunners() 方法5.4 排序调用图5.5 排序的根源 findOrder() 方法 一、简介 Order是 spring-core 包下的一个注解。Order 作用是定义 Spring IOC 容器中 Bean 的执行顺序。 注意 Spring 的 Order 注解或者 Ordered 接口不决定 Bean 的加载顺序和实例化顺序只决定 Bean 注入到 List 中的顺序。 Order 注解接受一个整数值作为参数数值越小表示优先级越高。当存在多个具有 Order 注解的组件时Spring Boot将按照数值从小到大的顺序加载它们。 需要注意的是 Order 注解只能用于标记 Spring 容器中的组件而不适用于标记普通的类。因此在使用 Order 注解时确保你的组件被正确地注册到 Spring 容器中。Order 注解只决定Bean的注入顺序并不保证实际执行的顺序。例如在 Web 应用中Filter 的执行顺序并不受 Order 注解影响。如果需要确保 Filter 按照顺序执行可以使用 FilterRegistrationBean 来设置 Filter 的顺序。 二、List 注入使用示例 包结构如下 2.1 测试接口类 IOrderTest 接口中定义了一个 handle() 方法用于测试。 IOrderTest.java /*** p Title IOrderTest* p Description Order注解测试接口** author ACGkaka* date 2023/10/17 11:20*/ public interface IOrderTest {/*** 处理*/void handle(); }2.2 测试接口实现类1 Order注解测试实现类01 和 Order注解测试实现类02 实现了 IOrderTest 接口用于测试 Order 的生效。 OrderTestImpl01.java import com.demo.test.IOrderTest; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component;/*** p Title OrderTestA* p Description Order注解测试实现类01** author ACGkaka* date 2023/10/17 11:18*/ Order(1) Component public class OrderTestImpl01 implements IOrderTest {public OrderTestImpl01() {System.out.println( OrderTestImpl01 constructor() );}Overridepublic void handle() {System.out.println( OrderTestImpl01 handle() );} }2.3 测试接口实现类2 Order注解测试实现类01 和 Order注解测试实现类02 实现了 IOrderTest 接口用于测试 Order 的生效。 OrderTestImpl02.java import com.demo.test.IOrderTest; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component;/*** p Title OrderTestImpl02* p Description Order注解测试实现类02** author ACGkaka* date 2023/10/17 11:18*/ Order(2) Component public class OrderTestImpl02 implements IOrderTest {public OrderTestImpl02() {System.out.println( OrderTestImpl02 constructor() );}Overridepublic void handle() {System.out.println( OrderTestImpl02 handle() );} }2.4 启动类测试 SpringbootDemoApplication.java import com.demo.test.IOrderTest; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean;import java.util.List;SpringBootApplication public class SpringbootDemoApplication {public static void main(String[] args) {SpringApplication.run(SpringbootDemoApplication.class, args);}Beanpublic CommandLineRunner commandLineRunner(ListIOrderTest list) {return args - {System.out.println( CommandLineRunner );list.forEach(IOrderTest::handle);};} }2.5 测试结果 场景一 Order(1) 注解修饰 OrderTestImpl01.javaOrder(2) 注解修饰 OrderTestImpl02.java 执行结果如下 场景二 Order(1) 注解修饰 OrderTestImpl02.javaOrder(2) 注解修饰 OrderTestImpl01.java 执行结果如下 三、CommandLineRunner 使用示例 3.1 接口实现类1 CommandLineRunner01.java import org.springframework.boot.CommandLineRunner; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component;/*** p Title CommandLineRunner01* p Description Order注解测试01** author ACGkaka* date 2023/10/17 11:20*/ Component Order(1) public class CommandLineRunner01 implements CommandLineRunner {Overridepublic void run(String... args) {System.out.println( CommandLineRunner01 );} }3.2 接口实现类2 CommandLineRunner02.java import org.springframework.boot.CommandLineRunner; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component;/*** p Title CommandLineRunner02* p Description Order注解测试02** author ACGkaka* date 2023/10/17 11:20*/ Component Order(2) public class CommandLineRunner02 implements CommandLineRunner {Overridepublic void run(String... args) {System.out.println( CommandLineRunner02 );} }3.3 测试结果 场景一 Order(1) 注解修饰 CommandLineRunner01.javaOrder(2) 注解修饰 CommandLineRunner02.java 执行结果如下 场景二 Order(1) 注解修饰 CommandLineRunner02.javaOrder(2) 注解修饰 CommandLineRunner01.java 执行结果如下 四、Order失效场景 失效场景 在 Configuration 里面通过 Bean 方式创建 Bean在上面加 Order 控制顺序是没有效果的。 4.1 失效代码示例 SpringbootDemoApplication.java import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.core.annotation.Order;SpringBootApplication public class SpringbootDemoApplication {public static void main(String[] args) {SpringApplication.run(SpringbootDemoApplication.class, args);}Order(2)Beanpublic CommandLineRunner commandLineRunner01() {return args - System.out.println( commandLineRunner01 );}Order(1)Beanpublic CommandLineRunner commandLineRunner02() {return args - System.out.println( commandLineRunner02 );} }4.2 执行结果 由下图可知虽然我们使用 Order 注解明确声明要先执行 commandLineRunner02但是并没有生效。 4.3 失效场景补救 在 Order 注解失效的场景下可以通过以下方式来控制顺序 方式一 可以通过具体实现类的方式创建 Bean用 Order Component 注解修饰。方式二 可以通过 RegistrationBean 方式创建 Bean用 setOrder 添加顺序。方式三 filter 可以通过 FilterRegistrationBean 创建 filter 的 Bean用 setOrder 添加顺序。 五、Order、Priority底层原理 看完 Order 注解的时候可能会疑惑 IOC 容器时如何通过 Order 注解来控制程序的先后顺序的接下来我们从源码层面看下容器是如何加载的。 先说结论 Order 底层是在 Bean 注入 IOC 容器之后执行的所以无法控制 Bean 的加载顺序。Order 底层是通过 List.sort(Comparator) 实现的AnnotationAwareOrderComparator 类集成 OrderComparator 类通过获取注解的 value 值实现了比对逻辑。 5.1 平平无奇的启动类 SpringbootDemoApplication.java SpringBootApplication public class SpringbootDemoApplication {public static void main(String[] args) {SpringApplication.run(SpringbootDemoApplication.class, args);} }5.2 神奇的 run() 方法 SpringApplication.run() public ConfigurableApplicationContext run(String... args) {StopWatch stopWatch new StopWatch();stopWatch.start();ConfigurableApplicationContext context null;CollectionSpringBootExceptionReporter exceptionReporters new ArrayList();configureHeadlessProperty();SpringApplicationRunListeners listeners getRunListeners(args);listeners.starting();try {ApplicationArguments applicationArguments new DefaultApplicationArguments(args);ConfigurableEnvironment environment prepareEnvironment(listeners, applicationArguments);configureIgnoreBeanInfo(environment);Banner printedBanner printBanner(environment);context createApplicationContext();exceptionReporters getSpringFactoriesInstances(SpringBootExceptionReporter.class,new Class[] { ConfigurableApplicationContext.class }, context);prepareContext(context, environment, listeners, applicationArguments, printedBanner);refreshContext(context);afterRefresh(context, applicationArguments);stopWatch.stop();if (this.logStartupInfo) {new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), stopWatch);}listeners.started(context);// #### 重点调用具体的执行方法 ###callRunners(context, applicationArguments);}catch (Throwable ex) {handleRunFailure(context, ex, exceptionReporters, listeners);throw new IllegalStateException(ex);}try {listeners.running(context);}catch (Throwable ex) {handleRunFailure(context, ex, exceptionReporters, null);throw new IllegalStateException(ex);}return context; }5.3 开始排序的 callRunners() 方法 SpringApplication.callRunners() private void callRunners(ApplicationContext context, ApplicationArguments args) {ListObject runners new ArrayList();runners.addAll(context.getBeansOfType(ApplicationRunner.class).values());runners.addAll(context.getBeansOfType(CommandLineRunner.class).values());// ### 重点按照定义的优先级顺序排序 ###AnnotationAwareOrderComparator.sort(runners);for (Object runner : new LinkedHashSet(runners)) {if (runner instanceof ApplicationRunner) {callRunner((ApplicationRunner) runner, args);}if (runner instanceof CommandLineRunner) {callRunner((CommandLineRunner) runner, args);}} }5.4 排序调用图 由于剩下的实现内容调用链比较长为了看起来更清晰直观采用顺序图展现出来 #mermaid-svg-091ep2ylgaclhhBs {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-091ep2ylgaclhhBs .error-icon{fill:#552222;}#mermaid-svg-091ep2ylgaclhhBs .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-091ep2ylgaclhhBs .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-091ep2ylgaclhhBs .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-091ep2ylgaclhhBs .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-091ep2ylgaclhhBs .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-091ep2ylgaclhhBs .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-091ep2ylgaclhhBs .marker{fill:#333333;stroke:#333333;}#mermaid-svg-091ep2ylgaclhhBs .marker.cross{stroke:#333333;}#mermaid-svg-091ep2ylgaclhhBs svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-091ep2ylgaclhhBs .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-091ep2ylgaclhhBs text.actortspan{fill:black;stroke:none;}#mermaid-svg-091ep2ylgaclhhBs .actor-line{stroke:grey;}#mermaid-svg-091ep2ylgaclhhBs .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-091ep2ylgaclhhBs .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-091ep2ylgaclhhBs #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-091ep2ylgaclhhBs .sequenceNumber{fill:white;}#mermaid-svg-091ep2ylgaclhhBs #sequencenumber{fill:#333;}#mermaid-svg-091ep2ylgaclhhBs #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-091ep2ylgaclhhBs .messageText{fill:#333;stroke:#333;}#mermaid-svg-091ep2ylgaclhhBs .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-091ep2ylgaclhhBs .labelText,#mermaid-svg-091ep2ylgaclhhBs .labelTexttspan{fill:black;stroke:none;}#mermaid-svg-091ep2ylgaclhhBs .loopText,#mermaid-svg-091ep2ylgaclhhBs .loopTexttspan{fill:black;stroke:none;}#mermaid-svg-091ep2ylgaclhhBs .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-091ep2ylgaclhhBs .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-091ep2ylgaclhhBs .noteText,#mermaid-svg-091ep2ylgaclhhBs .noteTexttspan{fill:black;stroke:none;}#mermaid-svg-091ep2ylgaclhhBs .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-091ep2ylgaclhhBs .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-091ep2ylgaclhhBs .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-091ep2ylgaclhhBs .actorPopupMenu{position:absolute;}#mermaid-svg-091ep2ylgaclhhBs .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4));}#mermaid-svg-091ep2ylgaclhhBs .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-091ep2ylgaclhhBs .actor-man circle,#mermaid-svg-091ep2ylgaclhhBs line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-091ep2ylgaclhhBs :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} SpringApplication AnnotationAwareOrderComparator List OrderComparator OrderUtils run() callRunners() sort() sort() compare() doCompare() getOrder() findOrder() findOrderFromAnnotation() getOrderFromAnnotations() findOrder() SpringApplication AnnotationAwareOrderComparator List OrderComparator OrderUtils 5.5 排序的根源 findOrder() 方法 获取 Order 注解的 value 值来进行排序。 OrderUtils.findOrder() Nullable private static Integer findOrder(MergedAnnotations annotations) {MergedAnnotationOrder orderAnnotation annotations.get(Order.class);if (orderAnnotation.isPresent()) {// ### 重点获取Order注解的value值return orderAnnotation.getInt(MergedAnnotation.VALUE);}MergedAnnotation? priorityAnnotation annotations.get(JAVAX_PRIORITY_ANNOTATION);if (priorityAnnotation.isPresent()) {// ### 重点获取Priority注解的value值return priorityAnnotation.getInt(MergedAnnotation.VALUE);}return null; }整理完毕完结撒花~ 参考地址 1.浅谈Spring Order注解的使用https://blog.csdn.net/yaomingyang/article/details/86649072 2.深入理解Spring的Order注解和Ordered接口https://blog.csdn.net/zkc7441976/article/details/112548075 3.踩坑Order失效。。。https://blog.csdn.net/qq_34142184/article/details/126951618
http://www.pierceye.com/news/268783/

相关文章:

  • 平湖网站设计北京广告公司名录
  • 不良网站进入窗口免费正能量安全的南昌网站制作
  • 商品交换电子商务网站开发网站首页制作公司
  • wordpress全站备份建设网站和推广
  • 广州市官网网站建设哪家好上海营销型网站建设公司
  • 江山网站制作瑞安自适应网站建设
  • 生意网官方网站高端建设网站
  • 公司网站建设南宁腾讯企业邮箱登录入口手机版
  • 简历网站推荐做网站公司是干什么的
  • 网站备案率是什么会展相关app和网站的建设情况
  • 南京网站设计网站建设上海网站域名备案处
  • 做网站市场分析三视觉平面设计网
  • 网站建设中++模板企业网站部署计划
  • 房产部门成立网站wordpress站内搜索次数
  • 网站建设合同管辖地广州敏城建设工程有限公司网站
  • 班级网站主页设计模板购买网站域名空间
  • 做响应式网站最大宽度景观设计公司起名
  • 有小广告的网站适合40岁女人的培训班
  • html5网站建设有什么网站用名字做图片
  • 合肥珍岛公司做网站推广怎么样关键词排名优化如何
  • 做讲课ppt的网站郑州市建设局官方网站
  • 邢台集团网站建设报价免费推广网站有哪些
  • 龙华网站建设营销推广广东东莞区号
  • 徐汇网站开发培训企业建网站报价
  • 专业网站建设公司兴田德润信任高建设高端网站公司哪家好
  • 烟台网站建设优惠臻动传媒做网站怎么挣钱
  • 重庆网站建设mlfartwordpress4 中文
  • 永州建设企业网站阿里云 网站部署
  • 学校做网站难吗创新logo设计
  • 国内用python做的网站如何做网站讯息