@DependsOn用於強制初始化其他Bean。可以修飾Bean類或方法,使用該Annotation時可以指定一個字符串數組作為參數,每個數組元素對應於一個強制初始化的Bean。
@DependsOn({"steelAxe","abc"}) @Component public class Chinese implements Person{ //codes here }
@Lazy用於指定該Bean是否取消預初始化。主要用於修飾Spring Bean類,用於指定該Bean的預初始化行為,使用該Annotation時可以指定一個boolean型的value屬性,該屬性決定是否要預初始化該Bean。
@Lazy(true) @Component public class Chinese implements Person{ //codes here }
啦啦啦
Class : SpringDynamicCornTask
package com.xindatai.ibs.lime.dycSchedul; import org.springframework.context.annotation.Lazy; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.SchedulingConfigurer; import org.springframework.scheduling.config.ScheduledTaskRegistrar; import org.springframework.stereotype.Component; @Lazy(false) @Component @EnableScheduling public class SpringDynamicCornTask implements SchedulingConfigurer { @Override public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { // TODO Auto-generated method stub } }
啦啦啦