Comprehensive application framework and inversion of control container for the Java platform providing dependency injection, AOP, data access, transaction management, and web framework capabilities
The Spring Core Container is the foundation of the Spring Framework, providing the Inversion of Control (IoC) container and dependency injection capabilities. It consists of three main modules: spring-core, spring-beans, and spring-context.
<!-- Core container with application context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.39</version>
</dependency>
<!-- For minimal IoC container only -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.3.39</version>
</dependency>// Application Context and Configuration
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
// Configuration Annotations
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
// Dependency Injection
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
// Component Stereotypes
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Repository;
// Bean Factory Interfaces
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
// Resource and Environment
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.env.Environment;
// Application Startup Metrics (Spring 5.3+)
import org.springframework.core.metrics.ApplicationStartup;
import org.springframework.core.metrics.StartupStep;
import org.springframework.core.metrics.DefaultApplicationStartup;
import org.springframework.core.metrics.jfr.FlightRecorderApplicationStartup;
// Reactive Type Adapters
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.core.ReactiveAdapter;
import org.springframework.core.ReactiveTypeDescriptor;
import org.springframework.context.annotation.PropertySource;The core module provides fundamental utilities, I/O abstractions, and type resolution.
// Encapsulates Java Type information with generic support
public class ResolvableType {
public static ResolvableType forClass(Class<?> clazz);
public static ResolvableType forInstance(Object instance);
public ResolvableType[] getGenerics();
public Class<?> getRawClass();
public ResolvableType getSuperType();
public ResolvableType[] getInterfaces();
}
// Helper for resolving method parameters and return types
public class MethodParameter {
public MethodParameter(Method method, int parameterIndex);
public MethodParameter(Constructor<?> constructor, int parameterIndex);
public Class<?> getParameterType();
public Type getGenericParameterType();
public String getParameterName();
public ResolvableType getResolvableType();
}// Interface for instrumenting application startup phases
public interface ApplicationStartup {
ApplicationStartup DEFAULT = new DefaultApplicationStartup();
StartupStep start(String name);
}
// Step recording metrics about a particular phase during startup
public interface StartupStep {
String getName();
long getId();
StartupStep.Tags getTags();
void end();
// Nested interface for step metadata
interface Tags {
Tags tag(String key, String value);
Tags tag(String key, Supplier<String> value);
}
}
// Default no-op implementation
public class DefaultApplicationStartup implements ApplicationStartup {
@Override
public StartupStep start(String name);
}
// Flight Recorder implementation for JFR integration
public class FlightRecorderApplicationStartup implements ApplicationStartup {
@Override
public StartupStep start(String name);
}// Registry of adapters to adapt Reactive Streams Publisher to/from various async/reactive types
public class ReactiveAdapterRegistry {
public static ReactiveAdapterRegistry getSharedInstance();
public void registerReactiveType(ReactiveTypeDescriptor descriptor,
Function<Object, Publisher<?>> toAdapter,
Function<Publisher<?>, Object> fromAdapter);
@Nullable
public ReactiveAdapter getAdapter(Class<?> reactiveType);
@Nullable
public ReactiveAdapter getAdapter(@Nullable Class<?> reactiveType, @Nullable Object source);
}
// Adapter for converting between Reactive Streams Publisher and async/reactive types
public class ReactiveAdapter {
public ReactiveTypeDescriptor getDescriptor();
public Publisher<?> toPublisher(Object source);
public Object fromPublisher(Publisher<?> publisher);
}
// Descriptor for reactive types (Mono, Flux, Observable, etc.)
public class ReactiveTypeDescriptor {
public static ReactiveTypeDescriptor singleOptionalValue(Class<?> type, Supplier<Object> emptySupplier);
public static ReactiveTypeDescriptor multiValue(Class<?> type, Supplier<Object> emptySupplier);
public static ReactiveTypeDescriptor noValue(Class<?> type, Supplier<Object> emptySupplier);
public Class<?> getReactiveType();
public boolean isMultiValue();
public boolean isNoValue();
public boolean supportsEmpty();
}// Interface for abstracting access to low-level resources
public interface Resource extends InputStreamSource {
boolean exists();
boolean isReadable();
boolean isOpen();
URL getURL() throws IOException;
URI getURI() throws IOException;
File getFile() throws IOException;
long contentLength() throws IOException;
long lastModified() throws IOException;
String getFilename();
String getDescription();
}
// Strategy interface for loading resources
public interface ResourceLoader {
String CLASSPATH_URL_PREFIX = "classpath:";
Resource getResource(String location);
ClassLoader getClassLoader();
}
// Common Resource implementations
public class ClassPathResource implements Resource {
public ClassPathResource(String path);
public ClassPathResource(String path, Class<?> clazz);
public ClassPathResource(String path, ClassLoader classLoader);
}
public class FileSystemResource implements Resource {
public FileSystemResource(String path);
public FileSystemResource(File file);
public FileSystemResource(Path path);
}
public class UrlResource extends AbstractResource {
public UrlResource(URL url);
public UrlResource(String protocol, String location);
}// Interface representing the environment with profiles and properties
public interface Environment extends PropertyResolver {
String[] getActiveProfiles();
String[] getDefaultProfiles();
boolean acceptsProfiles(String... profiles);
boolean acceptsProfiles(Profiles profiles);
}
// Interface for resolving properties against any underlying source
public interface PropertyResolver {
boolean containsProperty(String key);
String getProperty(String key);
String getProperty(String key, String defaultValue);
<T> T getProperty(String key, Class<T> targetType);
<T> T getProperty(String key, Class<T> targetType, T defaultValue);
String resolvePlaceholders(String text);
String resolveRequiredPlaceholders(String text) throws IllegalArgumentException;
}
// Abstract base class representing a source of name/value property pairs
public abstract class PropertySource<T> {
public PropertySource(String name, T source);
public String getName();
public T getSource();
public abstract Object getProperty(String name);
}The beans module provides the IoC container implementation and bean lifecycle management.
// Root interface for accessing Spring bean container
public interface BeanFactory {
String FACTORY_BEAN_PREFIX = "&";
Object getBean(String name) throws BeansException;
<T> T getBean(String name, Class<T> requiredType) throws BeansException;
Object getBean(String name, Object... args) throws BeansException;
<T> T getBean(Class<T> requiredType) throws BeansException;
<T> T getBean(Class<T> requiredType, Object... args) throws BeansException;
boolean containsBean(String name);
boolean isSingleton(String name) throws NoSuchBeanDefinitionException;
boolean isPrototype(String name) throws NoSuchBeanDefinitionException;
boolean isTypeMatch(String name, ResolvableType typeToMatch) throws NoSuchBeanDefinitionException;
Class<?> getType(String name) throws NoSuchBeanDefinitionException;
String[] getAliases(String name);
}
// Extension for factories that can enumerate all beans
public interface ListableBeanFactory extends BeanFactory {
boolean containsBeanDefinition(String beanName);
int getBeanDefinitionCount();
String[] getBeanDefinitionNames();
String[] getBeanNamesForType(Class<?> type);
String[] getBeanNamesForType(ResolvableType type);
<T> Map<String, T> getBeansOfType(Class<T> type) throws BeansException;
String[] getBeanNamesForAnnotation(Class<? extends Annotation> annotationType);
Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType) throws BeansException;
<A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType) throws NoSuchBeanDefinitionException;
}
// Configuration interface for most bean factories
public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, SingletonBeanRegistry {
String SCOPE_SINGLETON = "singleton";
String SCOPE_PROTOTYPE = "prototype";
void setParentBeanFactory(BeanFactory parentBeanFactory) throws IllegalStateException;
void setBeanClassLoader(ClassLoader beanClassLoader);
ClassLoader getBeanClassLoader();
void addBeanPostProcessor(BeanPostProcessor beanPostProcessor);
int getBeanPostProcessorCount();
void registerScope(String scopeName, Scope scope);
String[] getRegisteredScopeNames();
Scope getRegisteredScope(String scopeName);
}// Describes a bean instance with property values and constructor arguments
public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
String SCOPE_SINGLETON = ConfigurableBeanFactory.SCOPE_SINGLETON;
String SCOPE_PROTOTYPE = ConfigurableBeanFactory.SCOPE_PROTOTYPE;
String getBeanClassName();
void setBeanClassName(String beanClassName);
String getScope();
void setScope(String scope);
boolean isLazyInit();
void setLazyInit(boolean lazyInit);
String[] getDependsOn();
void setDependsOn(String... dependsOn);
boolean isAutowireCandidate();
void setAutowireCandidate(boolean autowireCandidate);
String getInitMethodName();
void setInitMethodName(String initMethodName);
String getDestroyMethodName();
void setDestroyMethodName(String destroyMethodName);
ConstructorArgumentValues getConstructorArgumentValues();
MutablePropertyValues getPropertyValues();
}
// Holder for BeanDefinition with name and aliases
public class BeanDefinitionHolder implements BeanMetadataElement {
public BeanDefinitionHolder(BeanDefinition beanDefinition, String beanName);
public BeanDefinitionHolder(BeanDefinition beanDefinition, String beanName, String[] aliases);
public BeanDefinition getBeanDefinition();
public String getBeanName();
public String[] getAliases();
}// Factory hook for custom modification of new bean instances
public interface BeanPostProcessor {
default Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
default Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
}
// Subinterface that adds before-instantiation callback
public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
default Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
return null;
}
default boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
return true;
}
default PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {
return pvs;
}
}
// Factory hook for custom modification of application context's bean definitions
public interface BeanFactoryPostProcessor {
void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException;
}// Marks constructor, field, or method as to be autowired
@Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Autowired {
boolean required() default true;
}
// Qualifier annotation for specifying which bean to inject
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface Qualifier {
String value() default "";
}
// Indicates default value expression for field or parameter
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Value {
String value();
}The context module provides the ApplicationContext and additional enterprise services.
// Central interface providing configuration for an application
public interface ApplicationContext extends EnvironmentCapable, ListableBeanFactory, HierarchicalBeanFactory,
MessageSource, ApplicationEventPublisher, ResourcePatternResolver {
String getId();
String getApplicationName();
String getDisplayName();
long getStartupDate();
ApplicationContext getParent();
AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException;
}
// Configuration interface for most application contexts
public interface ConfigurableApplicationContext extends ApplicationContext, Lifecycle, Closeable {
String CONFIG_LOCATION_DELIMITERS = ",; \t\n";
String CONVERSION_SERVICE_BEAN_NAME = "conversionService";
String LOAD_TIME_WEAVER_BEAN_NAME = "loadTimeWeaver";
String ENVIRONMENT_BEAN_NAME = "environment";
String SYSTEM_PROPERTIES_BEAN_NAME = "systemProperties";
String SYSTEM_ENVIRONMENT_BEAN_NAME = "systemEnvironment";
void setId(String id);
void setParent(ApplicationContext parent);
void setEnvironment(ConfigurableEnvironment environment);
ConfigurableEnvironment getEnvironment();
void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor);
void addApplicationListener(ApplicationListener<?> listener);
void refresh() throws BeansException, IllegalStateException;
void registerShutdownHook();
void close();
boolean isActive();
ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException;
}
// Standalone application context accepting annotated classes as input
public class AnnotationConfigApplicationContext extends GenericApplicationContext implements AnnotationConfigRegistry {
public AnnotationConfigApplicationContext();
public AnnotationConfigApplicationContext(DefaultListableBeanFactory beanFactory);
public AnnotationConfigApplicationContext(Class<?>... annotatedClasses);
public AnnotationConfigApplicationContext(String... basePackages);
public void register(Class<?>... annotatedClasses);
public void scan(String... basePackages);
}// Indicates that a class declares one or more @Bean methods
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Configuration {
@AliasFor(annotation = Component.class)
String value() default "";
boolean proxyBeanMethods() default true;
}
// Indicates that a method produces a bean to be managed by Spring container
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Bean {
@AliasFor("name")
String[] value() default {};
String[] name() default {};
Autowire autowire() default Autowire.NO;
boolean autowireCandidate() default true;
String initMethod() default "";
String destroyMethod() default AbstractBeanDefinition.INFER_METHOD;
}
// Configures component scanning directives
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Repeatable(ComponentScans.class)
public @interface ComponentScan {
@AliasFor("basePackages")
String[] value() default {};
String[] basePackages() default {};
Class<?>[] basePackageClasses() default {};
Class<? extends BeanNameGenerator> nameGenerator() default BeanNameGenerator.class;
Class<? extends ScopeMetadataResolver> scopeResolver() default AnnotationScopeMetadataResolver.class;
ScopedProxyMode scopedProxy() default ScopedProxyMode.DEFAULT;
String resourcePattern() default ClassPathScanningCandidateComponentProvider.DEFAULT_RESOURCE_PATTERN;
boolean useDefaultFilters() default true;
Filter[] includeFilters() default {};
Filter[] excludeFilters() default {};
boolean lazyInit() default false;
}// Indicates that an annotated class is a "component"
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Indexed
public @interface Component {
String value() default "";
}
// Indicates that an annotated class is a "Service"
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Service {
@AliasFor(annotation = Component.class)
String value() default "";
}
// Indicates that an annotated class is a "Repository"
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Repository {
@AliasFor(annotation = Component.class)
String value() default "";
}// Class to be extended by all application events
public abstract class ApplicationEvent extends EventObject {
public ApplicationEvent(Object source);
public final long getTimestamp();
}
// Interface to be implemented by application event listeners
@FunctionalInterface
public interface ApplicationListener<E extends ApplicationEvent> extends EventListener {
void onApplicationEvent(E event);
}
// Interface that encapsulates event publication functionality
@FunctionalInterface
public interface ApplicationEventPublisher {
default void publishEvent(ApplicationEvent event) {
publishEvent((Object) event);
}
void publishEvent(Object event);
}
// Annotation-based event listener
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface EventListener {
@AliasFor("classes")
Class<?>[] value() default {};
Class<?>[] classes() default {};
String condition() default "";
}// Java configuration approach
@Configuration
@ComponentScan(basePackages = "com.example")
public class AppConfig {
@Bean
public DataSource dataSource() {
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName("org.h2.Driver");
ds.setUrl("jdbc:h2:mem:testdb");
return ds;
}
@Bean
public PlatformTransactionManager transactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
}
// Application startup
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
// Retrieve beans
UserService userService = ctx.getBean(UserService.class);
DataSource dataSource = ctx.getBean(DataSource.class);
// Use the beans
User user = userService.findById(1L);
// Clean shutdown
((ConfigurableApplicationContext) ctx).close();
}
}// Constructor injection (recommended)
@Service
public class UserService {
private final UserRepository userRepository;
private final EmailService emailService;
// @Autowired optional on single constructor
public UserService(UserRepository userRepository, EmailService emailService) {
this.userRepository = userRepository;
this.emailService = emailService;
}
public User createUser(User user) {
User saved = userRepository.save(user);
emailService.sendWelcomeEmail(saved);
return saved;
}
}
// Field injection with qualifiers
@Component
public class NotificationManager {
@Autowired
@Qualifier("emailNotifier")
private Notifier emailNotifier;
@Autowired
@Qualifier("smsNotifier")
private Notifier smsNotifier;
public void sendNotification(String message, NotificationType type) {
switch (type) {
case EMAIL:
emailNotifier.send(message);
break;
case SMS:
smsNotifier.send(message);
break;
}
}
}
// Multiple implementations with qualifiers
@Component
@Qualifier("emailNotifier")
public class EmailNotifier implements Notifier {
public void send(String message) {
// Send email
}
}
@Component
@Qualifier("smsNotifier")
public class SmsNotifier implements Notifier {
public void send(String message) {
// Send SMS
}
}// Property source configuration
@Configuration
@PropertySource("classpath:application.properties")
@PropertySource("classpath:database.properties")
public class PropertyConfig {
@Autowired
private Environment env;
@Bean
public DatabaseConfig databaseConfig() {
DatabaseConfig config = new DatabaseConfig();
config.setUrl(env.getProperty("db.url"));
config.setUsername(env.getProperty("db.username"));
config.setPassword(env.getProperty("db.password"));
config.setMaxConnections(env.getProperty("db.maxConnections", Integer.class, 10));
return config;
}
}
// Value injection in components
@Component
public class EmailService {
@Value("${email.smtp.host}")
private String smtpHost;
@Value("${email.smtp.port:587}")
private int smtpPort;
@Value("${email.from}")
private String fromAddress;
public void sendEmail(String to, String subject, String body) {
// Use injected properties
}
}// Environment-specific beans
@Configuration
public class ProfileConfig {
@Bean
@Profile("development")
public DataSource devDataSource() {
return new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.addScript("classpath:schema.sql")
.addScript("classpath:test-data.sql")
.build();
}
@Bean
@Profile("production")
public DataSource prodDataSource() {
HikariDataSource dataSource = new HikariDataSource();
dataSource.setJdbcUrl("jdbc:postgresql://prod-db:5432/myapp");
dataSource.setUsername("produser");
dataSource.setPassword("prodpass");
dataSource.setMaximumPoolSize(20);
return dataSource;
}
@Bean
@Profile({"development", "test"})
public MailSender mockMailSender() {
return new MockMailSender();
}
@Bean
@Profile("production")
public MailSender realMailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("smtp.company.com");
return mailSender;
}
}// Lifecycle interfaces
@Component
public class DatabaseConnectionManager implements InitializingBean, DisposableBean {
private Connection connection;
@Override
public void afterPropertiesSet() throws Exception {
// Initialize connection after properties are set
this.connection = DriverManager.getConnection("jdbc:h2:mem:testdb");
System.out.println("Database connection established");
}
@Override
public void destroy() throws Exception {
// Clean up resources
if (connection != null && !connection.isClosed()) {
connection.close();
System.out.println("Database connection closed");
}
}
}
// Annotation-based lifecycle
@Component
public class CacheManager {
private Map<String, Object> cache;
@PostConstruct
public void initializeCache() {
this.cache = new ConcurrentHashMap<>();
loadInitialData();
System.out.println("Cache initialized");
}
@PreDestroy
public void clearCache() {
if (cache != null) {
cache.clear();
System.out.println("Cache cleared");
}
}
private void loadInitialData() {
// Load initial cache data
}
}
// Bean method lifecycle configuration
@Configuration
public class ServiceConfig {
@Bean(initMethod = "start", destroyMethod = "stop")
public NetworkService networkService() {
return new NetworkService();
}
}// Custom FactoryBean
@Component
public class ConnectionFactoryBean implements FactoryBean<Connection> {
@Value("${db.url}")
private String url;
@Value("${db.username}")
private String username;
@Value("${db.password}")
private String password;
@Override
public Connection getObject() throws Exception {
return DriverManager.getConnection(url, username, password);
}
@Override
public Class<?> getObjectType() {
return Connection.class;
}
@Override
public boolean isSingleton() {
return false; // New connection each time
}
}
// Custom scope (thread scope example)
public class ThreadScope implements Scope {
private final ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal<Map<String, Object>>() {
@Override
protected Map<String, Object> initialValue() {
return new HashMap<>();
}
};
@Override
public Object get(String name, ObjectFactory<?> objectFactory) {
Map<String, Object> scope = threadLocal.get();
Object obj = scope.get(name);
if (obj == null) {
obj = objectFactory.getObject();
scope.put(name, obj);
}
return obj;
}
@Override
public Object remove(String name) {
return threadLocal.get().remove(name);
}
@Override
public void registerDestructionCallback(String name, Runnable callback) {
// Implementation depends on requirements
}
@Override
public Object resolveContextualObject(String key) {
return null;
}
@Override
public String getConversationId() {
return Thread.currentThread().getName();
}
}
// Register custom scope
@Configuration
public class ScopeConfig implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
beanFactory.registerScope("thread", new ThreadScope());
}
}// Bean creation failures
try {
MyService service = applicationContext.getBean(MyService.class);
} catch (NoSuchBeanDefinitionException e) {
// Bean not found
log.error("Bean not found: " + e.getMessage());
} catch (NoUniqueBeanDefinitionException e) {
// Multiple beans found when expecting one
log.error("Multiple beans found: " + e.getMessage());
} catch (BeanCreationException e) {
// Bean creation failed
log.error("Bean creation failed: " + e.getMessage(), e);
} catch (UnsatisfiedDependencyException e) {
// Dependency injection failed
log.error("Unsatisfied dependency: " + e.getMessage(), e);
}
// ApplicationContext initialization
try {
ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
} catch (BeanDefinitionStoreException e) {
// Invalid bean definitions
log.error("Invalid bean definition: " + e.getMessage(), e);
} catch (ApplicationContextException e) {
// Context initialization failed
log.error("Context initialization failed: " + e.getMessage(), e);
}The Core Container provides the foundation for all Spring applications, offering powerful dependency injection, comprehensive lifecycle management, and flexible configuration options through annotations or Java configuration classes.
Install with Tessl CLI
npx tessl i tessl/maven-org-springframework--spring