Spring Framework integration support for caching (Caffeine, JCache), mail (JavaMail), scheduling (Quartz), and template engines (FreeMarker)
npx @tessl/cli install tessl/maven-org-springframework--spring-context-support@6.2.00
# Spring Context Support
1
2
Spring Context Support provides comprehensive integration support for external libraries and frameworks, enabling seamless integration of caching, mail, scheduling, and template processing capabilities into Spring applications. It bridges Spring's core dependency injection and application context features with popular third-party libraries.
3
4
## Package Information
5
6
- **Package Name**: spring-context-support
7
- **Package Type**: maven
8
- **Language**: Java
9
- **Installation**:
10
```xml
11
<dependency>
12
<groupId>org.springframework</groupId>
13
<artifactId>spring-context-support</artifactId>
14
<version>6.2.8</version>
15
</dependency>
16
```
17
18
Gradle:
19
```kotlin
20
implementation("org.springframework:spring-context-support:6.2.8")
21
```
22
23
## Core Imports
24
25
```java
26
// Cache support
27
import org.springframework.cache.caffeine.CaffeineCacheManager;
28
import org.springframework.cache.jcache.JCacheCacheManager;
29
import org.springframework.cache.transaction.TransactionAwareCacheManagerProxy;
30
31
// Mail support
32
import org.springframework.mail.MailSender;
33
import org.springframework.mail.SimpleMailMessage;
34
import org.springframework.mail.javamail.JavaMailSender;
35
import org.springframework.mail.javamail.JavaMailSenderImpl;
36
import org.springframework.mail.javamail.MimeMessageHelper;
37
38
// Scheduling support
39
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
40
import org.springframework.scheduling.quartz.QuartzJobBean;
41
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
42
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
43
44
// Template support
45
import org.springframework.ui.freemarker.FreeMarkerConfigurationFactory;
46
import org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean;
47
```
48
49
## Basic Usage
50
51
```java
52
// Cache configuration
53
@Configuration
54
@EnableCaching
55
public class CacheConfig {
56
57
@Bean
58
public CacheManager cacheManager() {
59
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
60
cacheManager.setCaffeine(Caffeine.newBuilder()
61
.maximumSize(1000)
62
.expireAfterWrite(Duration.ofMinutes(10)));
63
return cacheManager;
64
}
65
}
66
67
// Mail configuration
68
@Configuration
69
public class MailConfig {
70
71
@Bean
72
public JavaMailSender mailSender() {
73
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
74
mailSender.setHost("smtp.example.com");
75
mailSender.setPort(587);
76
mailSender.setUsername("user@example.com");
77
mailSender.setPassword("password");
78
return mailSender;
79
}
80
}
81
82
// Using mail sender
83
@Service
84
public class EmailService {
85
86
@Autowired
87
private JavaMailSender mailSender;
88
89
public void sendEmail(String to, String subject, String text) {
90
SimpleMailMessage message = new SimpleMailMessage();
91
message.setTo(to);
92
message.setSubject(subject);
93
message.setText(text);
94
mailSender.send(message);
95
}
96
}
97
```
98
99
## Architecture
100
101
Spring Context Support is organized around four main integration areas:
102
103
- **Caching**: Provides implementations for Caffeine and JCache/JSR-107 cache providers, plus transaction-aware caching decorators
104
- **Mail**: Offers abstraction layer over JavaMail with support for simple text messages and complex MIME messages
105
- **Scheduling**: Integrates with Quartz scheduler for enterprise-grade job scheduling and management
106
- **Templates**: Enables FreeMarker template engine integration for server-side rendering
107
108
Each area provides both high-level convenience APIs and lower-level configuration options for advanced use cases.
109
110
## Capabilities
111
112
### Caching Support
113
114
Comprehensive caching integration with multiple providers including Caffeine, JCache/JSR-107, and transaction-aware caching. Enables high-performance caching strategies with Spring's declarative caching annotations.
115
116
```java { .api }
117
// Caffeine Cache Manager
118
public class CaffeineCacheManager extends AbstractCacheManager {
119
public void setCaffeine(Caffeine<Object, Object> caffeine);
120
public void setAsyncCacheMode(boolean asyncCacheMode);
121
public void setAllowNullValues(boolean allowNullValues);
122
}
123
124
// JCache Manager
125
public class JCacheCacheManager extends AbstractTransactionSupportingCacheManager {
126
public void setCacheManager(javax.cache.CacheManager cacheManager);
127
public javax.cache.CacheManager getCacheManager();
128
}
129
130
// Transaction-aware caching
131
public class TransactionAwareCacheManagerProxy implements CacheManager, InitializingBean {
132
public void setTargetCacheManager(CacheManager targetCacheManager);
133
}
134
```
135
136
[Caching Support](./caching.md)
137
138
### Mail Integration
139
140
Complete mail functionality from simple text messages to complex MIME messages with attachments. Provides abstraction over JavaMail with Spring-friendly configuration and error handling.
141
142
```java { .api }
143
// Core mail interfaces
144
public interface MailSender {
145
void send(SimpleMailMessage simpleMessage) throws MailException;
146
void send(SimpleMailMessage... simpleMessages) throws MailException;
147
}
148
149
public interface JavaMailSender extends MailSender {
150
MimeMessage createMimeMessage();
151
MimeMessage createMimeMessage(InputStream contentStream) throws MailException;
152
void send(MimeMessage mimeMessage) throws MailException;
153
void send(MimeMessage... mimeMessages) throws MailException;
154
void send(MimeMessagePreparator mimeMessagePreparator) throws MailException;
155
void send(MimeMessagePreparator... mimeMessagePreparators) throws MailException;
156
}
157
158
// Main implementation
159
public class JavaMailSenderImpl implements JavaMailSender {
160
public void setHost(String host);
161
public void setPort(int port);
162
public void setUsername(String username);
163
public void setPassword(String password);
164
public void setJavaMailProperties(Properties javaMailProperties);
165
}
166
```
167
168
[Mail Integration](./mail.md)
169
170
### Quartz Scheduling
171
172
Enterprise-grade job scheduling integration with Quartz Scheduler. Supports cron-based triggers, method-invoking jobs, and full Spring dependency injection for scheduled tasks.
173
174
```java { .api }
175
// Main scheduler factory
176
public class SchedulerFactoryBean implements FactoryBean<Scheduler>, BeanNameAware,
177
ApplicationContextAware, InitializingBean, DisposableBean, SmartLifecycle {
178
public void setConfigLocation(Resource configLocation);
179
public void setQuartzProperties(Properties quartzProperties);
180
public void setTriggers(Trigger... triggers);
181
public void setJobDetails(JobDetail... jobDetails);
182
public void setAutoStartup(boolean autoStartup);
183
}
184
185
// Job creation
186
public class JobDetailFactoryBean implements FactoryBean<JobDetail>, BeanNameAware, InitializingBean {
187
public void setJobClass(Class<? extends Job> jobClass);
188
public void setJobDataAsMap(Map<String, ?> jobDataAsMap);
189
}
190
191
// Base job class
192
public abstract class QuartzJobBean implements Job {
193
protected abstract void executeInternal(JobExecutionContext context) throws JobExecutionException;
194
}
195
```
196
197
[Quartz Scheduling](./scheduling.md)
198
199
### FreeMarker Templates
200
201
Template engine integration for server-side rendering with FreeMarker. Provides factory beans for configuration and utilities for template processing in web and non-web contexts.
202
203
```java { .api }
204
// Configuration factory
205
public class FreeMarkerConfigurationFactory {
206
public void setTemplateLoaderPath(String templateLoaderPath);
207
public void setTemplateLoaderPaths(String... templateLoaderPaths);
208
public void setFreemarkerSettings(Properties settings);
209
public void setDefaultEncoding(String defaultEncoding);
210
public Configuration createConfiguration() throws IOException, TemplateException;
211
}
212
213
// Factory Bean wrapper
214
public class FreeMarkerConfigurationFactoryBean extends FreeMarkerConfigurationFactory
215
implements FactoryBean<Configuration>, InitializingBean, ResourceLoaderAware {
216
}
217
218
// Template utilities
219
public abstract class FreeMarkerTemplateUtils {
220
public static String processTemplateIntoString(Template template, Object model)
221
throws IOException, TemplateException;
222
}
223
```
224
225
[FreeMarker Templates](./templates.md)
226
227
## Exception Handling
228
229
All modules provide comprehensive exception hierarchies extending from Spring's base exception classes:
230
231
- **Mail exceptions**: `MailException` base class with `MailAuthenticationException`, `MailSendException`, `MailParseException`, `MailPreparationException`
232
- **Scheduling exceptions**: `JobMethodInvocationFailedException` for method-invoking job failures
233
- **Cache exceptions**: Standard Spring Cache abstraction exceptions
234
- **Template exceptions**: Standard FreeMarker `TemplateException` and `IOException`