CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-springframework-boot--spring-boot-autoconfigure

Spring Boot AutoConfigure provides auto-configuration capabilities that automatically configure Spring applications based on jar dependencies present on the classpath

Pending
Overview
Eval results
Files

additional-features.mddocs/reference/

Additional Features

Spring Boot AutoConfigure provides additional configuration support for JMX management, logging, application info, cache management, and pre-initialization features.

Imports

import org.springframework.boot.autoconfigure.jmx.*;
import org.springframework.boot.autoconfigure.logging.*;
import org.springframework.boot.autoconfigure.info.*;
import org.springframework.boot.autoconfigure.cache.*;
import org.springframework.boot.autoconfigure.preinitialize.*;
import org.springframework.boot.autoconfigure.context.*;

JMX Configuration

JmxProperties

Configuration properties for JMX (Java Management Extensions) support.

@ConfigurationProperties("spring.jmx")
public class JmxProperties {
    /**
     * Whether to enable JMX support.
     * Default is false.
     */
    public boolean isEnabled();
    public void setEnabled(boolean enabled);

    /**
     * Whether to use unique runtime object names.
     * Default is false.
     */
    public boolean isUniqueNames();
    public void setUniqueNames(boolean uniqueNames);

    /**
     * MBeanServer bean name.
     * Default is "mbeanServer".
     */
    public String getServer();
    public void setServer(String server);

    /**
     * Set the default JMX domain.
     */
    public void setDefaultDomain(String defaultDomain);

    /**
     * Registration policy for MBeans.
     */
    public RegistrationPolicy getRegistrationPolicy();
    public void setRegistrationPolicy(RegistrationPolicy registrationPolicy);

    /**
     * Registration policy options.
     */
    public enum RegistrationPolicy {
        FAIL_ON_EXISTING,
        IGNORE_EXISTING,
        REPLACE_EXISTING
    }
}

ParentAwareNamingStrategy

Extension of MetadataNamingStrategy that supports a parent ApplicationContext for hierarchical JMX naming.

public class ParentAwareNamingStrategy extends MetadataNamingStrategy {
    /**
     * Set whether to ensure unique runtime object names.
     */
    public void setEnsureUniqueRuntimeObjectNames(boolean ensureUniqueRuntimeObjectNames);

    /**
     * Set the application context.
     */
    public void setApplicationContext(ApplicationContext applicationContext);

    /**
     * Get the JMX ObjectName for the given managed bean.
     */
    public ObjectName getObjectName(Object managedBean, String beanKey)
        throws MalformedObjectNameException;
}

Logging Configuration

ConditionEvaluationReportLoggingListener

ApplicationContextInitializer that writes the ConditionEvaluationReport to the log.

public class ConditionEvaluationReportLoggingListener
        implements ApplicationContextInitializer<ConfigurableApplicationContext>,
                   GenericApplicationListener {

    /**
     * Create a listener with custom log level.
     */
    public static ConditionEvaluationReportLoggingListener forLogLevel(LogLevel logLevelForReport);

    /**
     * Initialize the application context.
     */
    public void initialize(ConfigurableApplicationContext applicationContext);

    /**
     * Get the order of this listener.
     */
    public int getOrder();

    /**
     * Check if this listener supports the given event type.
     */
    public boolean supportsEventType(ResolvableType resolvableType);

    /**
     * Check if this listener supports the given source type.
     */
    public boolean supportsSourceType(Class<?> sourceType);

    /**
     * Handle an application event.
     */
    public void onApplicationEvent(ApplicationEvent event);
}

ConditionEvaluationReportMessage

A condition evaluation report message that can be logged or printed.

public class ConditionEvaluationReportMessage {
    /**
     * Create a new message for the given report.
     */
    public ConditionEvaluationReportMessage(ConditionEvaluationReport report);

    /**
     * Create a new message for the given report with custom log level.
     */
    public ConditionEvaluationReportMessage(ConditionEvaluationReport report, LogLevel logLevel);

    /**
     * Get the string representation of the report.
     */
    public String toString();
}

Application Info Configuration

ProjectInfoProperties

Configuration properties for project information including build and git metadata.

@ConfigurationProperties(prefix = "spring.info")
public class ProjectInfoProperties {
    /**
     * Get build information configuration.
     */
    public Build getBuild();

    /**
     * Get git information configuration.
     */
    public Git getGit();

    /**
     * Build information configuration.
     */
    public static class Build {
        /**
         * Location of the build info properties file.
         * Default is "classpath:META-INF/build-info.properties".
         */
        public Resource getLocation();
        public void setLocation(Resource location);

        /**
         * File encoding for build info.
         */
        public Charset getEncoding();
        public void setEncoding(Charset encoding);
    }

    /**
     * Git information configuration.
     */
    public static class Git {
        /**
         * Location of the git properties file.
         * Default is "classpath:git.properties".
         */
        public Resource getLocation();
        public void setLocation(Resource location);

        /**
         * File encoding for git info.
         */
        public Charset getEncoding();
        public void setEncoding(Charset encoding);
    }
}

Context Configuration

LifecycleProperties

Configuration properties for lifecycle processing and shutdown behavior.

@ConfigurationProperties("spring.lifecycle")
public class LifecycleProperties {
    /**
     * Timeout for each shutdown phase.
     * Default is 30 seconds.
     */
    public Duration getTimeoutPerShutdownPhase();
    public void setTimeoutPerShutdownPhase(Duration timeoutPerShutdownPhase);
}

MessageSourceProperties

Configuration properties for message source internationalization.

@ConfigurationProperties("spring.messages")
public class MessageSourceProperties {
    /**
     * Get the comma-separated list of basenames.
     * Default is "messages".
     */
    public List<String> getBasename();
    public void setBasename(List<String> basename);

    /**
     * Message bundles encoding.
     * Default is UTF-8.
     */
    public Charset getEncoding();
    public void setEncoding(Charset encoding);

    /**
     * Get the cache duration for loaded resource bundles.
     * Null means cache forever.
     */
    public @Nullable Duration getCacheDuration();

    /**
     * Set the cache duration for loaded resource bundles.
     * Null means cache forever.
     */
    public void setCacheDuration(@Nullable Duration cacheDuration);

    /**
     * Whether to fall back to the system Locale if no files found for specific Locale.
     * Default is true.
     */
    public boolean isFallbackToSystemLocale();
    public void setFallbackToSystemLocale(boolean fallbackToSystemLocale);

    /**
     * Whether to always apply the MessageFormat rules.
     * Default is false.
     */
    public boolean isAlwaysUseMessageFormat();
    public void setAlwaysUseMessageFormat(boolean alwaysUseMessageFormat);

    /**
     * Whether to use the message code as the default message.
     * Default is false.
     */
    public boolean isUseCodeAsDefaultMessage();
    public void setUseCodeAsDefaultMessage(boolean useCodeAsDefaultMessage);

    /**
     * Get the list of locale-independent property file resources containing common messages.
     */
    public @Nullable List<Resource> getCommonMessages();

    /**
     * Set common messages shared across all locales.
     */
    public void setCommonMessages(@Nullable List<Resource> commonMessages);
}

Cache Configuration

CacheType Enum

Enum defining supported cache types in order of precedence.

public enum CacheType {
    /**
     * Generic caching using ConcurrentHashMap.
     */
    GENERIC,

    /**
     * JCache (JSR-107) EHCache, Hazelcast, Infinispan, etc.
     */
    JCACHE,

    /**
     * Hazelcast distributed cache.
     */
    HAZELCAST,

    /**
     * Infinispan cache.
     */
    INFINISPAN,

    /**
     * Couchbase cache.
     */
    COUCHBASE,

    /**
     * Redis cache.
     */
    REDIS,

    /**
     * Cache2k cache.
     */
    CACHE2K,

    /**
     * Caffeine cache.
     */
    CAFFEINE,

    /**
     * Simple cache using ConcurrentHashMap.
     */
    SIMPLE,

    /**
     * No caching.
     */
    NONE
}

Pre-initialization

BackgroundPreinitializer

Interface for pre-initializing code in the background that may otherwise cause delays. Implementations should be registered in spring.factories.

public interface BackgroundPreinitializer {
    /**
     * Perform background pre-initialization.
     * Called early in application startup to warm up expensive initializations.
     */
    void preinitialize();
}

Configuration Examples

JMX Configuration

spring:
  jmx:
    enabled: true
    unique-names: true
    server: mbeanServer
    default-domain: com.example.app
    registration-policy: replace_existing

Message Source Configuration

spring:
  messages:
    basename: messages,config.i18n.messages
    encoding: UTF-8
    cache-duration: 3600s
    fallback-to-system-locale: true
    always-use-message-format: false
    use-code-as-default-message: false

Application Info Configuration

spring:
  info:
    build:
      location: classpath:META-INF/build-info.properties
      encoding: UTF-8
    git:
      location: classpath:git.properties
      encoding: UTF-8

Lifecycle Configuration

spring:
  lifecycle:
    timeout-per-shutdown-phase: 60s

Usage Examples

JMX Management

import org.springframework.boot.autoconfigure.jmx.JmxProperties;
import org.springframework.jmx.export.MBeanExporter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JmxConfiguration {

    @Bean
    public MBeanExporter mbeanExporter(JmxProperties jmxProperties) {
        MBeanExporter exporter = new MBeanExporter();
        exporter.setEnsureUniqueRuntimeObjectNames(jmxProperties.isUniqueNames());
        exporter.setRegistrationPolicy(jmxProperties.getRegistrationPolicy());
        return exporter;
    }
}

Condition Evaluation Logging

import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener;
import org.springframework.boot.logging.LogLevel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class LoggingConfiguration {

    @Bean
    public ConditionEvaluationReportLoggingListener reportListener() {
        return ConditionEvaluationReportLoggingListener.forLogLevel(LogLevel.DEBUG);
    }
}

Message Source Internationalization

import org.springframework.boot.autoconfigure.context.MessageSourceProperties;
import org.springframework.context.MessageSource;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MessageSourceConfiguration {
    private final MessageSourceProperties properties;

    public MessageSourceConfiguration(MessageSourceProperties properties) {
        this.properties = properties;
    }

    @Bean
    public MessageSource messageSource() {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        messageSource.setBasenames(
            properties.getBasename().toArray(new String[0])
        );
        messageSource.setDefaultEncoding(properties.getEncoding().name());
        messageSource.setFallbackToSystemLocale(
            properties.isFallbackToSystemLocale()
        );
        return messageSource;
    }
}

Custom Background Pre-initializer

import org.springframework.boot.autoconfigure.preinitialize.BackgroundPreinitializer;

public class DatabaseConnectionPreinitializer implements BackgroundPreinitializer {

    @Override
    public void preinitialize() {
        // Warm up database driver
        try {
            Class.forName("org.postgresql.Driver");
            System.out.println("Database driver pre-initialized");
        } catch (ClassNotFoundException e) {
            // Handle error
        }
    }
}

Register in META-INF/spring.factories:

org.springframework.boot.autoconfigure.preinitialize.BackgroundPreinitializer=\
com.example.DatabaseConnectionPreinitializer

Cache Type Selection

import org.springframework.boot.autoconfigure.cache.CacheType;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableCaching
public class CacheConfiguration {

    @Bean
    public CacheManager cacheManager() {
        // Choose cache implementation based on requirements
        return new ConcurrentMapCacheManager("users", "products");
    }
}

Best Practices

  1. JMX: Enable only in environments that need monitoring
  2. Logging: Use DEBUG level for condition evaluation reports in development
  3. Messages: Configure proper encoding for international character sets
  4. Lifecycle: Set appropriate shutdown timeout for graceful shutdown
  5. Cache: Choose cache type based on scalability requirements
  6. Pre-initialization: Use for expensive one-time initializations
  7. Build Info: Include build-info plugin in production builds for versioning

Install with Tessl CLI

npx tessl i tessl/maven-org-springframework-boot--spring-boot-autoconfigure

docs

index.md

tile.json