spring 注解

1.@ConditionalOnClass

作用:引入相关包才会构建类。

例:引入jackson的ObjectMapper才会构建JacksonConfig

@Configuration
@ConditionalOnClass(ObjectMapper.class)
@AutoConfigureBefore(JacksonAutoConfiguration.class)
public class JacksonConfig {

	private static final String ASIA_SHANGHAI = "Asia/Shanghai";

	@Bean
	@ConditionalOnMissingBean
	public Jackson2ObjectMapperBuilderCustomizer customizer() {
		return builder -> {
			builder.locale(Locale.CHINA);
			builder.timeZone(TimeZone.getTimeZone(ASIA_SHANGHAI));
			builder.simpleDateFormat(DatePattern.NORM_DATETIME_PATTERN);
			builder.modules(new PigxJavaTimeModule());
		};
	}

}

2.@AutoConfigureBefore、@AutoConfigureAfter

作用:在***类之前/之后加载。是 spring-boot-autoconfigure 包下的注解

例:在AAAA之前加载,@AutoConfigureBefore(AAAA.class) 或 AutoConfigureBefore({AAAA.class, BBBB.class})

@AutoConfigureBefore(AAAA.class)
public class CCCC {
}

在AAAA之后加载,@AutoConfigureAfter(AAAA.class) 或 AutoConfigureAfter({AAAA.class, BBBB.class})

@AutoConfigureAfter(AAAA.class)
public class CCCC {
}
上一篇:MySQL表与数据向Oracle移植(使用Oracle SQL Developer工具)


下一篇:多war包部署在一个tomcat中