Home / Class/ StructuredLoggingJsonPropertiesBeanFactoryInitializationAotProcessor Class — spring-boot Architecture

StructuredLoggingJsonPropertiesBeanFactoryInitializationAotProcessor Class — spring-boot Architecture

Architecture documentation for the StructuredLoggingJsonPropertiesBeanFactoryInitializationAotProcessor class in StructuredLoggingJsonPropertiesBeanFactoryInitializationAotProcessor.java from the spring-boot codebase.

Entity Profile

Source Code

core/spring-boot/src/main/java/org/springframework/boot/logging/structured/StructuredLoggingJsonPropertiesBeanFactoryInitializationAotProcessor.java lines 42–97

class StructuredLoggingJsonPropertiesBeanFactoryInitializationAotProcessor
		implements BeanFactoryInitializationAotProcessor {

	private static final String ENVIRONMENT_BEAN_NAME = "environment";

	@Override
	public @Nullable BeanFactoryInitializationAotContribution processAheadOfTime(
			ConfigurableListableBeanFactory beanFactory) {
		Environment environment = beanFactory.getBean(ENVIRONMENT_BEAN_NAME, Environment.class);
		StructuredLoggingJsonProperties properties = StructuredLoggingJsonProperties.get(environment);
		if (properties != null) {
			Set<Class<? extends StructuredLoggingJsonMembersCustomizer<?>>> customizers = properties.customizer();
			String stackTracePrinter = getCustomStackTracePrinter(properties);
			if (stackTracePrinter != null || !customizers.isEmpty()) {
				return new AotContribution(beanFactory.getBeanClassLoader(), customizers, stackTracePrinter);
			}
		}
		return null;
	}

	private static @Nullable String getCustomStackTracePrinter(StructuredLoggingJsonProperties properties) {
		StackTrace stackTrace = properties.stackTrace();
		return (stackTrace != null && stackTrace.hasCustomPrinter()) ? stackTrace.printer() : null;
	}

	private static final class AotContribution implements BeanFactoryInitializationAotContribution {

		private final @Nullable ClassLoader classLoader;

		private final Set<Class<? extends StructuredLoggingJsonMembersCustomizer<?>>> customizers;

		private final @Nullable String stackTracePrinter;

		private AotContribution(@Nullable ClassLoader classLoader,
				Set<Class<? extends StructuredLoggingJsonMembersCustomizer<?>>> customizers,
				@Nullable String stackTracePrinter) {
			this.classLoader = classLoader;
			this.customizers = customizers;
			this.stackTracePrinter = stackTracePrinter;
		}

		@Override
		public void applyTo(GenerationContext generationContext,
				BeanFactoryInitializationCode beanFactoryInitializationCode) {
			ReflectionHints reflection = generationContext.getRuntimeHints().reflection();
			this.customizers.forEach((customizer) -> reflection.registerType(customizer,
					MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS));
			if (this.stackTracePrinter != null) {
				reflection.registerTypeIfPresent(this.classLoader, this.stackTracePrinter,
						MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
			}
		}

	}

}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free