Line 1,086: | Line 1,086: | ||
| '''<tt>beans</tt>''' || style='white-space:nowrap' | <tt>http://www.springframework.org/schema/beans</tt> |
| '''<tt>beans</tt>''' || style='white-space:nowrap' | <tt>http://www.springframework.org/schema/beans</tt> |
||
| Defines the elements to define beans. |
| Defines the elements to define beans. |
||
− | | [https://github.com/spring-projects/spring-framework/blob/v4.2.4.RELEASE/spring-beans/src/main/resources/org/springframework/beans/factory/xml/spring-beans-4.0.xsd <tt> |
+ | | [https://github.com/spring-projects/spring-framework/blob/v4.2.4.RELEASE/spring-beans/src/main/resources/org/springframework/beans/factory/xml/spring-beans-4.0.xsd <tt>spring-beans-4.0.xsd</tt>] |
|- |
|- |
||
| '''<tt>context</tt>''' || style='white-space:nowrap' | <tt>http://www.springframework.org/schema/context</tt> |
| '''<tt>context</tt>''' || style='white-space:nowrap' | <tt>http://www.springframework.org/schema/context</tt> |
||
| Defines the configuration elements for the Spring Framework's application. |
| Defines the configuration elements for the Spring Framework's application. |
||
| [https://github.com/spring-projects/spring-framework/tree/master/spring-context/src/main/resources/org/springframework/context/config <tt>org.springframework.context.config</tt>] |
| [https://github.com/spring-projects/spring-framework/tree/master/spring-context/src/main/resources/org/springframework/context/config <tt>org.springframework.context.config</tt>] |
||
− | [https://github.com/spring-projects/spring-framework/blob/v4.2.4.RELEASE/spring-context/src/main/resources/org/springframework/context/config/spring-context-4.0.xsd <tt> |
+ | [https://github.com/spring-projects/spring-framework/blob/v4.2.4.RELEASE/spring-context/src/main/resources/org/springframework/context/config/spring-context-4.0.xsd <tt>spring-context-4.0.xsd</tt>] |
|- |
|- |
||
|- |
|- |
||
Line 1,097: | Line 1,097: | ||
| Defines the configuration elements for the Spring Framework's AOP support. |
| Defines the configuration elements for the Spring Framework's AOP support. |
||
| [https://github.com/spring-projects/spring-framework/tree/master/spring-aop/src/main/resources/org/springframework/aop/config <tt>org.springframework.aop.config</tt>] |
| [https://github.com/spring-projects/spring-framework/tree/master/spring-aop/src/main/resources/org/springframework/aop/config <tt>org.springframework.aop.config</tt>] |
||
− | [https://github.com/spring-projects/spring-framework/blob/v4.2.4.RELEASE/spring-aop/src/main/resources/org/springframework/aop/config/spring-aop-4.0.xsd <tt> |
+ | [https://github.com/spring-projects/spring-framework/blob/v4.2.4.RELEASE/spring-aop/src/main/resources/org/springframework/aop/config/spring-aop-4.0.xsd <tt>spring-aop-4.0.xsd</tt>] |
|} |
|} |
||
Revision as of 02:49, 27 March 2020
Overview
- Spring projects
- Spring documentation (quick access to API and reference documentation for all Spring projects)
- Raising Spring: An 18-Year Journey (Rod Johnson, Oct. 24, 19)
Spring Framework
- http://www.springsource.org/spring-framework
- Desc. : provides a comprehensive programming and configuration model for modern Java-based enterprise applications - on any kind of deployment platform.
- License :
- Sources : https://github.com/spring-projects/spring-framework
- Maven artifacts
References
- Spring Framework 5.0 Reference Documentation
- Spring Framework 5.0 API
- Spring Framework 4.3 Reference Documentation
- Spring Framework 4.3 API
- Spring Framework 4.2 Reference Documentation
- Spring Framework 4.2 API
- Spring Framework 4.1 Reference Documentation
- Spring Framework 4.1 API
- Spring Framework 4.0 Reference Documentation
- Spring Framework 4.0 API
- Spring Framework 3.2 Reference Documentation
- Spring Framework 3.2 API
- Spring Framework 3.1 Reference Documentation
- Spring Framework 3.1 API
- Spring Framework 3.0 Reference Documentation
- Spring Framework 3.0 API
General
- Inversion of Control Containers and the Dependency Injection pattern(Martin Fowler, 23 January 2004)
- Announcing Spring Framework 4.0 GA Release
- Setter injection versus constructor injection and the use of @Required(JULY 11, 2007)
- As of Spring 3.1, the Spring team generally advocates setter injection. because ...
- As of Spring 4.0, the Spring team generally advocates constructor injection as it enables ...
Notes
- Annotation injection is performed before XML injection, thus the latter configuration will override the former for properties wired through both approaches.
- The
@Required
annotation simply indicates that the affected bean property must be populated at configuration time, through an explicit property value in a bean definition or through autowiring. The container throws an exception if the affected bean property has not been populated; this allows for eager and explicit failure, avoiding NullPointerExceptions or the like later on. It is still recommended that you put assertions into the bean class itself, for example, into an init method. Doing so enforces those required references and values even when you use the class outside of a container.
Resource
Prefix | Example | Remarks |
---|---|---|
classpath: | classpath:com/myapp/config.xml | |
file: | file:///data/config.xml | |
http: | https://myserver/logo.png |
Class/Interface | Description | Remarks |
---|---|---|
Resource | Interface for a resource descriptor that abstracts from the actual type of underlying resource, such as a file or class path resource. | |
ClassPathResource | Resource implementation for class path resources. | |
FileSystemResource | Resource implementation for java.io.File and java.nio.file.Path handles with a file system target. | |
ResourceUtils | Utility methods for resolving resource locations to files in the file system. |
- Wildcards in application context constructor resource paths
classpath*:
,classpath:com/mycompany/**/applicationContext.xml
, ...
Container
ConfigurableApplicationContext
- Prefer
ConfigurableApplicationContext
toApplicationContext
- Pay attention to
registerShutdownHook()
method.
- Prefer
GenericXmlApplicationContext
DefaultResourceLoader
|
+----- AbstractApplicationContext
| |
| +----- AbstractRefreshableApplicationContext
| |
| +----- AbstractRefreshableConfigApplicationContext
| |
| +----- AbstractRefreshableWebApplicationContext
| | |
| | +----- AnnotationConfigWebApplicationContext
| | +----- GroovyWebApplicationContext
| | +----- XmlWebApplicationContext
| |
| +----- AbstractXmlApplicationContext
| | |
| | +------- ClassPathXmlApplicationContext
| | +------- FileSystemXmlApplicationContext
| |
| +----- AnnotationConfigReactiveWebApplicationContext
+----- GenericApplicationContext
|
+----- AnnotationConfigApplicationContext
+----- GenericGroovyApplicationContext
+----- GenericReactiveWebApplicationContext
| |
| +----- ReactiveWebServerApplicationContext
| |
| +----- AnnotationConfigReactiveWebServerApplicationContext
|
+----- GenericWebApplicationContext
| |
| +----- ServletWebServerApplicationContext
| |
| +----- AnnotationConfigServletWebServerApplicationContext
| +----- XmlServletWebServerApplicationContext
|
+----- GenericXmlApplicationContext
+----- ResourceAdapterApplicationContext
+----- StaticApplicationContext
|
+----- StaticWebApplicationContext
Configuration
- Annotation-based Container Configuration
- @Required, @Autowired, @Inject, @Named
- Annotation injection is performed before XML injection. Thus, the XML configuration overrides the annotations for properties wired through both approaches.
- The @Required annotation is formally deprecated as of Spring Framework 5.1, in favor of using constructor injection for required settings.
- Java-based Container Configuration
- @Configuration, @Bean, @PropertySource
- The @Bean annotation is used to indicate that a method instantiates, configures, and initializes a new object to be managed by the Spring IoC container.
- The @Bean annotation plays the same role as the <bean/> element.
- Annotating a class with @Configuration indicates that its primary purpose is as a source of bean definitions.
- Spring Component Scan Include and Exclude Filter Example (June 24, 2019)
API
Annotation | Package | Annotations | Remarks |
---|---|---|---|
@Configuration | o.s.context.annotation | Indicates that a class declares one or more @Bean methods and may be processed by the Spring container to generate bean definitions and service requests for those beans at runtime. | @Component |
@ComponentScan | o.s.context.annotation | Configures component scanning directives for use with @Configuration classes. | <context:component-scan> |
@Import | o.s.context.annotation | Indicates one or more @Configuration classes to import. | |
@EnableAsync | o.s.scheduling.annotation | Enables Spring's asynchronous method execution capability. | @Async |
@EnableScheduling | o.s.scheduling.annotation | Enables Spring's scheduled task execution capability. | @Scheduled |
@SpringBootApplication | o.s.boot.autoconfigure | Indicates a configuration class that declares one or more @Bean methods and also triggers auto-configuration and component scanning | @Configuration, @EnableAutoConfiguration, @ComponentScan |
@EnableAutoConfiguration | o.s.boot.autoconfigure | Enable auto-configuration of the Spring Application Context, attempting to guess and configure beans that you are likely to need. | exclude, excludeName |
Properties
- Properties with Spring(October 15, 2013)
- Example: the Class name substitution PropertyPlaceholderConfigurer
- Using Spring and Commons Configuration (Jul 11th, 2008)
- Nested Property Placeholders in Spring Configuration (February 25, 2008)
- How to programmatically resolve property placeholder in Spring(Mar 2 '11)
- Bean definition profiles
- Not loading a Spring bean when a certain profile is set (Aug 1 '14)
- Encrypting application configuration files using Jasypt
API
Item | Type | Description | Remarks |
---|---|---|---|
PropertyPlaceholderConfigurer | class | ||
PropertySourcesPlaceholderConfigurer | class | ||
PropertiesLoaderSupport.setLocalOverride(boolean localOverride) | method | ||
EmbeddedValueResolverAware | class | ||
propertyPlaceholder type | XML | ||
property-placeholder element | XML |
Benas
MethodInvokingFactoryBean
- returns a value which is the result of a static or instance method invocation.
MethodInvokingBean
- just invoking a target method, not expecting a result to expose to the container.
<bean id="registeringIdentificationListener" class="org.springframework.beans.factory.config.MethodInvokingBean"
depends-on="listenableDetectionService, defaultDetectionListener">
<property name="targetObject" ref="listenableDetectionService"/>
<property name="targetMethod" value="addListener"/>
<property name="arguments" ref="defaultDetectionListener"/>
</bean>
- Wiring collections
<list/>, <set/>,
, and<props/>
- Declaring an array of objects in a Spring bean context(Aug 31 '10)
- Using MethodInvokingFactoryBean to set up unconventional beans(Mar 23 '11)
- Spring Annotation Programming Model (8 Jun 2016)
@Required
@Autowired
@Resource
@Inject
and@Named
- Spring annotations vs. Standard annotations
@Autowired, @Component, @Component, @Inject, @Required, ...
- Spring Injection with @Resource, @Autowired and @Inject (2011)
- Combining lifecycle mechanisms using
@PostConstruct
and@PreDestroy
javax.annotation
package of Java SE 6 (contains@PostConstruct
,@PreDestroy
and@Resource
)
- Spring: Using @Qualifier with Property Placeholder (Aug 13 '13)
- @Resource(name="${qualifier}")
API
Class | Package | Description | Remarks |
---|---|---|---|
@Bean | o.s.context.annotation | Indicates that a method produces a bean to be managed by the Spring container. | @Configuration |
@Component | o.s.stereotype | Indicates that an annotated class is a "component". Such classes are considered as candidates for auto-detection when using annotation-based configuration and classpath scanning. | @ComponentScan |
@Required | o.s.beans.factory.annotation | Marks a method (typically a JavaBean setter method) as being 'required': that is, the setter method must be configured to be dependency-injected with a value. | Deprecated as of 5.1 |
@Autowired | o.s.beans.factory.annotation | Marks a constructor, field, setter method, or config method as to be autowired by Spring's dependency injection facilities. | JSR-330 @Inject |
@Primary | o.s.context.annotation | Indicates that a bean should be given preference when multiple candidates are qualified to autowire a single-valued dependency. | |
@Qualifier | o.s.beans.factory.annotation | This annotation may be used on a field or parameter as a qualifier for candidate beans when autowiring. | |
@Resource | javax.annotation | The Resource annotation marks a resource that is needed by the application. | @Autowired |
@ManagedBean | javax.annotation | The ManagedBean annotation marks a POJO as a ManagedBean.A ManagedBean supports a small set of basic services such as resource injection, lifecycle callbacks and interceptors. | @Component |
@Named | javax.inject | String-based qualifier. | |
@Inject | javax.inject | Identifies injectable constructors, methods, and fields. | @Autowired |
@Scope | |||
@Lazy | |||
@PostConstruct | |||
@PreDestroy | |||
@Conditional | o.s.context.annotation | Indicates that a component is only eligible for registration when all specified conditions match. | |
@Profile | o.s.context.annotation | Indicates that a component is eligible for registration when one or more specified profiles are active. | |
@ConditionalOnProperty | o.s.b.autoconfigure.condition | Conditional that checks if the specified properties have a specific value. |
Annotations
Purpose | Package | Annotations |
---|---|---|
Denoting the roles of types or methods in the overall architecture | o.s.stereotype
|
@Component , @Controller , @Repository , @Service
|
Bean configuration
|
o.s.beans.factory.annotation
|
@Autowired , @Required , @Value , ...
|
ApplicationContext support
|
o.s.context.annotation
|
@Bean , @ComponentScan , @Conditional , @Configuration , @Lazy , @Profile , @Scope , ...
|
Asynchronous method execution | o.s.scheduling.annotation
|
@Async , @Scheduled
|
Binding requests to controllers and handler methods | o.s.web.bind.annotation
|
@RestController , @GetMapping , @PostMapping , @PutMapping , @PathVariable , @RequestBody , @ResponseBody , ...
|
Transaction demarcation | o.s.transaction.annotation
|
@Transactional , @EnableTransactionManagement
|
Annotation-driven tests | o.s.test.annotation
|
@IfProfileValue , @Repeat , @Rollback , @Timed
|
MBean exposure
|
o.s.jmx.export.annotation
|
@ManagedResource , @ManagedAttribute , @ManagedOperation
|
Declaratively configuring field formatting rules | o.s.format.annotation
|
@DateTimeFormat , @NumberFormat
|
Spring Boot's auto-configuration capabilities. | o.s.boot.autoconfigure
|
@EnableAutoConfiguration , @SpringBootApplication
|
SpEL
- Expression support for defining bean definitions
- Escaping Spring EL (2010)
- SpEL Predefined Variables (12-May-2011)
- SpEL
- How do I reference a bean in spring-el named with a prefix? (Jul 9 '13)
Transaction
- Using
@Transactional
- "Spring recommends that you only annotate concrete classes (and methods of concrete classes) with the
@Transactional
annotation, as opposed to annotating interfaces." - "When using proxies, you should apply the
@Transactional
annotation only to methods with public visibility." - "In proxy mode (which is the default), only external method calls coming in through the proxy are intercepted. This means that self-invocation, in effect, a method within the target object calling another method of the target object, will not lead to an actual transaction at runtime even if the invoked method is marked with
@Transactional
." - "
@EnableTransactionManagement
and<tx:annotation-driven/>
only looks for@Transactional
on beans in the same application context they are defined in." - Annotation driven transaction settings
- Use
aspectj
mode as possible.
- "Spring recommends that you only annotate concrete classes (and methods of concrete classes) with the
- Using
@Transactional
with AspectJ - SPRING DECLARATIVE TRANSACTION MANAGEMENT WITH JDK PROXY VS ASPECTJ(28 JUNE, 2014)
- Use compile-time weaving (not load-time weaving) with @aspectj@ mode to processing
@Transactional
annotations.
- Use compile-time weaving (not load-time weaving) with @aspectj@ mode to processing
- Distributed transactions in Spring, with and without XA
- XA transactions using Spring
- J2EE Without the Application Server
- Configuring Spring and JTA without full Java EE
- Understanding transaction pitfalls(February 03, 2009)
- Interesting points about the use of Spring Transactional (Jun 10, 2016)
- Spring does not support transactions propagation across remote calls
- Spring does not support self-invocation by default
- Spring only supports transactions in public methods
API
Class | Description | Remarks |
---|---|---|
@Transactional | Describes transaction attributes on a method or class. | |
@TransactionConfiguration | Defines class-level metadata for configuring transactional tests. | |
@Rollback | Indicate whether or not the transaction for the annotated test method should be rolled back after the test method has completed. |
AOP
Concurrency
- Task Execution and Scheduling
- 4 ways to schedule tasks in Spring 3 :
@Scheduled
example (April 23, 2013) - How to parameterize @Scheduled(fixedDelay) with Spring 3.0 expression language? (Apr 8 '10)
API
Class | Description | Remarks |
---|---|---|
TaskExecutor | Simple task executor interface that abstracts the execution of a Runnable. | |
ExecutorServiceAdapter | Adapter that takes a Spring TaskExecutor and exposes a full java.util.concurrent.ExecutorService for it. | |
ConcurrentTaskExecutor | Adapter that takes a java.util.concurrent.Executor and exposes a Spring TaskExecutor for it. | |
ThreadPoolTaskExecutor | JavaBean that allows for configuring a ThreadPoolExecutor in bean style (through its "corePoolSize", "maxPoolSize", "keepAliveSeconds", "queueCapacity" properties) and exposing it as a Spring TaskExecutor. | |
ThreadPoolExecutorFactoryBean | JavaBean that allows for configuring a ThreadPoolExecutor in bean style (through its "corePoolSize", "maxPoolSize", "keepAliveSeconds", "queueCapacity" properties) and exposing it as a bean reference of its native ExecutorService type. | |
@Scheduled | ||
@Async |
Internationalization
- Internationalization using MessageSource
- Spring Resource bundle with ResourceBundleMessageSource example (August 30, 2012)
API
Class | Description | Remarks |
---|---|---|
o.s.context.MessageSource | ||
o.s.context.support.ResourceBundleMessageSource | ||
o.s.context.support.ReloadableResourceBundleMessageSource |
Source
Web MVC
- Read HTTP Request Header in Spring MVC
- @RequestHeader
- Spring MVC - Binding HTTP request header attributes with @RequestHeader (Feb 17, 2016)
- How to Set a Header on a Response with Spring 5 (February 21, 2019)
- Spring MVC @RequestBody @ResponseBody Example (August 11, 2015)
API
Class | Package | Description | Remarks |
---|---|---|---|
HttpHeaders | javax.ws.rs.core | An injectable interface that provides access to HTTP header information. | |
HttpHeaders | o.s.http | A data structure representing HTTP request or response headers. | |
HttpHeaders | org.apache.http | Constants enumerating the HTTP headers. | RFC1945 (HTTP/1.0), RFC2616 (HTTP/1.1), RFC2518 (WebDAV) |
MediaType | javax.ws.rs.core | An abstraction for a media type. | |
MediaType | o.s.http | ||
ContentType | org.apache.http.entity | Content type information consisting of a MIME type and an optional charset. | |
HttpEntity<T> | o.s.http | ||
RequestEntity<T> | o.s.http | ||
ResponseEntity<T> | o.s.http | ||
@RequestMapping | o.s.web.bind.annotation | Annotation for mapping web requests onto methods in request-handling classes with flexible method signatures. | |
@GetMapping | o.s.web.bind.annotation | Annotation for mapping HTTP GET requests onto specific handler methods. | |
@PostMapping | o.s.web.bind.annotation | Annotation for mapping HTTP POST requests onto specific handler methods. | |
@PathVariable | o.s.web.bind.annotation | Annotation which indicates that a method parameter should be bound to a URI template variable. | |
@RequestParam | o.s.web.bind.annotation | Annotation which indicates that a method parameter should be bound to a web request parameter. | |
@RequestHeader | o.s.web.bind.annotation | Annotation which indicates that a method parameter should be bound to a web request header. | |
@SessionAttribute | o.s.web.bind.annotation | Annotation to bind a method parameter to a session attribute. | |
@RequestBody | o.s.web.bind.annotation | Annotation indicating a method parameter should be bound to the body of the web request. | |
colspan='4' | |||
CommonsRequestLoggingFilter | o.s.web.filter | Simple request logging filter that writes the request URI (and optionally the query string) to the Commons Log. |
- Spring @RequestParam Annotation
- Mapping All Parameters, Mapping a Multi-Value Parameter, ...
REST
- Spring Restfull Jax-RS annotation support (Aug 28 '14)
- No, you cannot use
javax.ws.*
annotations in spring.
- No, you cannot use
- Is RestTemplate thread safe? (Apr 10 '14)
- thread-safe once constructed
- REST in Spring 3: RestTemplate (MARCH 27, 2009)
- Spring Boot RestTemplate POST JSON Example
- Spring RestTemplate - how to enable full debugging/logging of requests/responses? (Oct 31 '11)
- logging.level.org.apache.http=DEBUG
- logging.level.org.apache.http.wire=DEBUG
Class | Description | Remark |
---|---|---|
RestTemplate (source) | Synchronous client to perform HTTP requests, exposing a simple, template method API over underlying HTTP client libraries such as the JDK HttpURLConnection, Apache HttpComponents, and others. | |
HttpComponentsClientHttpRequestFactory | ClientHttpRequestFactory implementation that uses Apache HttpComponents HttpClient to create requests. | |
SimpleClientHttpRequestFactory | ClientHttpRequestFactory implementation that uses standard JDK facilities. | |
Netty4ClientHttpRequestFactory | ClientHttpRequestFactory implementation that uses Netty 4 to create requests. | |
HttpMessageConverter<T> | ||
Jaxb2RootElementHttpMessageConverter | Implementation of HttpMessageConverter that can read and write XML using JAXB2. | |
MappingJackson2HttpMessageConverter (source) | Implementation of HttpMessageConverter that can read and write JSON using Jackson 2.x's ObjectMapper. | |
MappingJackson2XmlHttpMessageConverter | Implementation of HttpMessageConverter that can read and write XML using Jackson 2.x extension component for reading and writing XML encoded data. | |
MappingJackson2SmileHttpMessageConverter | Implementation of HttpMessageConverter that can read and write Smile data format ("binary JSON") using the dedicated Jackson 2.x extension. | |
Jackson2ObjectMapperBuilder | A builder used to create ObjectMapper instances with a fluent API. |
Exception Handling
- Exception Handling in Spring MVC (NOVEMBER 01, 2013)
- @CONTROLLERADVICE IMPROVEMENTS IN SPRING 4 (2013/11)
- Error Handling for REST with Spring (January 23, 2017)
org.springframework.web.servlet.handler.HandlerExceptionResolverComposite
APIorg.springframework.web.servlet.handler.HandlerExceptionResolverComposite
source
Filters
Class | Package | Description | Remarks |
---|---|---|---|
CommonsRequestLoggingFilter | o.s.web.filter | Simple request logging filter that writes the request URI (and optionally the query string) to the Commons Log. |
misc
- Learn to customize Spring MVC @Controller method arguments(November 8, 2009)
- Is RestTemplate thread safe? (Apr 10 '14)
- thread-safe once constructed
JMX
- ManagedResource Annotation is not annoted as Inherited
- We finally changed @ManagedResource to inherited now. Potential object name collisions need to be dealt with; the general recommendation is to not specify an object name value in @ManagedResource at all when using it on a base class.
API
org.springframework.jmx.export.MBeanExporter
public void destroy()
: Unregisters all beans that this exported has exposed via JMX when the enclosingApplicationContext
is destroyed.
Annotation | Package | Annotations | Remarks |
---|---|---|---|
@ManagedResource | o.s.jmx.export.annotation | Class-level annotation that indicates to register instances of a class with a JMX server, corresponding to the ManagedResource attribute. | |
@ManagedAttribute | o.s.jmx.export.annotation | Method-level annotation that indicates to expose a given bean property as a JMX attribute, corresponding to the ManagedAttribute attribute. | |
@ManagedOperation | o.s.jmx.export.annotation | Method-level annotation that indicates to expose a given method as a JMX operation, corresponding to the ManagedOperation attribute. |
Jackson
- Spring Framework 5.1 Documentation / eMail
- Spring Boot 2.1 Documentation / Sending Email
- org.springframework.boot.autoconfigure.mail.MailProperties (spring.mail)
- Guide to Spring Email (May 19, 2019)
Class/Interface | Description | Remarks |
---|---|---|
JavaMailSender | Extended MailSender interface for JavaMail, supporting MIME messages both as direct arguments and through preparation callbacks. | |
JavaMailSenderImpl (source) | Production implementation of the JavaMailSender interface, supporting both JavaMail MimeMessages and Spring SimpleMailMessages. | protected void doSend() |
SimpleMailMessage | Models a simple mail message, including data such as the from, to, cc, subject, and text fields. | |
MimeMessageHelper | Helper class for populating a MimeMessage. |
- Threadsafety in Javamail (Oct 4 '12)
- Session : thread-safe, Transport : NOT thread-safe, Store :
Class/Interface | Description | Remarks |
---|---|---|
javax.mail.Session | The Session class represents a mail session and is not subclassed. | A single default session can be shared by multiple applications on the desktop. Unshared sessions can also be created. |
javax.mail.Transport | An abstract class that models a message transport. |
- Email (on Wikipedia)
- RFC 5322 Internet Message Format
Field | Description | Remarks |
---|---|---|
From | The email address, and optionally the name of the author(s) | |
To | The email address(es), and optionally name(s) of the message's recipient(s) | Recipients |
Cc | Carbon copy recipients | |
Bcc | Blind carbon copy recipients | |
Date | The local time and date when the message was written. | |
Subject | A brief summary of the topic of the message. | |
Content-Type | Information about how the message is to be displayed, usually a MIME type | |
Message-ID | ||
In-Reply-To | Message-ID of the message that this is a reply to. | |
References | Message-ID of the message that this is a reply to, and the message-id of the message the previous reply was a reply to, etc. | |
Reply-To | Address that should be used to reply to the message. | |
Sender | Address of the actual sender acting on behalf of the author listed in the From: field |
misc
- Nested Property Placeholders in Spring Configuration
- Spring 3 MVC and JSON example
- Spring framework p notation schema example
- Logging Dependencies in Spring
- Using JCL, SLF4J or Log4j with Spring
- Embedded Db’s in Spring 3.0.(2011/05/02)
- Set System Property With Spring Configuration File (Jul 26 '10)
Spring Boot
- http://projects.spring.io/spring-boot/
- Desc. : makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".
- Sources : https://github.com/spring-projects/spring-boot
References
Spring Boot 2.1
Spring Boot 2.0
- Spring Boot 2.0 Reference Guide
- Spring Boot 2.0 API
- Spring Boot 2.0 Actuator Web API
- org.springframework.boot » spring-boot-starter-parent » 2.0.0 » pom.xml
- org.springframework.boot » spring-boot-dependencies » 2.0.0 » pom.xml
- org.springframework.boot.autoconfigure.SpringBootApplication
- a convenience annotation that is equivalent to declaring @Configuration, @EnableAutoConfiguration and @ComponentScan
- Common application properties
Spring Boot 1.5
- Spring Boot 1.5 Reference Guide
- Spring Boot 1.5 API
- org.springframework.boot » spring-boot-starter-parent » 1.5.1 » pom.xml
- org.springframework.boot » spring-boot-dependencies » 1.5.1 » pom.xml
- spring-boot-parent/pom.xml
- spring-boot-dependencies/pom.xml
General
- GETTING STARTED Building an Application with Spring Boot
- Spring Boot without the web server (Sep 29 '14)
- How to load Spring Boot Application Context while using Cucumber at runtime, not via tests? (Nov 15 '17)
Configuration
- Spring MVC auto-configuration
Converter
,GenericConverter
,Formatter
,HttpMessageConverters
,MessageCodesResolver
,ConfigurableWebBindingInitializer
- Condition annotations
- Class conditions, Bean conditions, Property conditions, Resource conditions, Web application conditions, SpEL expression conditions
org.springframework.boot.autoconfigure.condition
packageConditionalOnProperty
API
- Disabling Specific Auto-configuration Classes
- @EnableAutoConfiguration(exclude= {FreeMarkerAutoConfiguration.class})
- Multi-profile YAML Documents
- How to access a value defined in the application.properties file in Spring Boot (May 29 '15)
- @Value, Environment, @PropertySource
- Reading application.properties in Spring Boot (April 16, 2018)
- Read application.properties using Environment object.
- Read a property from application.properties file using @ConfigurationProperties
- and reading a property using the @Value annotation.
API
Class/Interface | Description | Remarks |
---|---|---|
WebMvcAutoConfiguration (source) | Auto-configuration for Web MVC. | localeResolver() |
MessageSourceAutoConfiguration (source) | Auto-configuration for MessageSource. | |
Environment | Interface representing the environment in which the current application is running. |
Actuator
- Spring Boot Actuator: Production-ready features
- Building a RESTful Web Service with Spring Boot Actuator
- Spring Boot 2.0 Migration Guide / Spring Boot Actuator
- Spring Boot Actuator (June 8, 2018)
- Spring Boot Actuator: A Complete Guide (Feb. 27, 17)
- Securing Actuator Endpoints
Error Control
Class | Package | Description | Remarks |
---|---|---|---|
BasicErrorController (source)
|
o.s.b.autoconfigure.web | ||
AbstractErrorController (source) | o.s.b.autoconfigure.web | ||
DefaultErrorAttributes (source) | o.s.b.autoconfigure.web |
REST
- Customize the Jackson ObjectMapper
- Spring From the Trenches: Parsing Date and Time Information From a Request Parameter (September 28, 2015)
- Configuring a global date & time format
- Parsing of LocalDate query parameters in Spring Boot (08/07/17)
- Set default format for LocalDateTime (jsr310) in spring when passed to a rest end point (Aug 27 '17)
Test
Spring Test
Class/Package | Description | Remarks |
---|---|---|
@ContextConfiguration | Defines class-level metadata that is used to determine how to load and configure an ApplicationContext for integration tests. | |
MockMvc | Main entry point for server-side Spring MVC test support. | |
SpringExtension | integrates the Spring TestContext Framework into JUnit 5's Jupiter programming model. | |
@SpringJUnitConfig | A composed annotation that combines @ExtendWith(SpringExtension.class) from JUnit Jupiter with @ContextConfiguration from the Spring TestContext Framework. |
- Context Configuration with Annotated Classes
- If you omit the classes attribute from the @ContextConfiguration annotation, the TestContext framework tries to detect the presence of default configuration classes. Specifically, AnnotationConfigContextLoader and AnnotationConfigWebContextLoader detect all static nested classes of the test class that meet the requirements for configuration class implementations, as specified in the @Configuration javadoc.
- Spring 3.1 M2: Testing with @Configuration Classes and Profiles (JUNE 21, 2011)
- How to Test the @Scheduled Annotation (February 21, 2019)
- Disable Test with Spring and Junit5 without context creation (Oct 9 '17)
- Spring @PropertySource using YAML (Jan 21 '14)
Spring Boot Test
Class/Package | Description | Remarks |
---|---|---|
@SpringBootTest | Annotation that can be specified on a test class that runs Spring Boot based tests. | |
enum SpringBootTest.WebEnvironment
|
An enumeration web environment modes | DEFINED_PORT , MOCK , NONE , RANDOM_PORT
|
@WebMvcTest | Using this annotation will disable full auto-configuration and instead apply only configuration relevant to MVC tests (@Controller but not @Component, @Service or @Repository | @AutoConfigureWebMvc, @AutoConfigureMockMvc |
@AutoConfigureMockMvc | Annotation that can be applied to a test class to enable and configure auto-configuration of MockMvc. | |
@MockBean | Annotation that can be used to add mocks to a Spring ApplicationContext. |
- Testing improvements in Spring Boot 1.4 (APRIL 15, 2016)
- Test that startup an Spring-boot application (Apr 7 '17)
webEnvironment
- Spring Boot and JUnit 5 (APRIL 12, 2017)
- Auto-configured Spring MVC Tests
- @WebMvcTest auto-configures the Spring MVC infrastructure and limits scanned beans to @Controller, @ControllerAdvice, @JsonComponent, Converter, GenericConverter, Filter, WebMvcConfigurer, and HandlerMethodArgumentResolver. Regular @Component beans are not scanned when using this annotation.
misc
- Configuring Logback With Spring Boot (Sep. 03, 17)
- USING YAML IN SPRING BOOT TO CONFIGURE LOGBACK (May 5, 2016)
- How do I set the Hibernate dialect in SpringBoot? (Jul 26 '16)
- spring.jpa.properties.hibernate.dialect
- spring.jpa.database-platform
- Spring Boot - How to log all requests and responses with exceptions in single place? (Apr 26 '17)
- CommonsRequestLoggingFilter
Spring Security
- http://projects.spring.io/spring-security/
- Desc. : a powerful and highly customizable authentication and access-control framework.
- Sources : https://github.com/spring-projects/spring-security
- Maven artifacts
References
Spring Security 5.1
Spring Security 4.2.2
Spring Security 3.1
Concepts
- Access control in computer security
- ACL(Access Control List)
- JAAS(Java Authentication and Authorization Service)
- Spring Security Core Components :
SecurityContext
,Authentication
,GrantedAuthority
,UserDetails
,UserDetailsService
Concept | Description | API | Remarks |
---|---|---|---|
Principal | the abstract notion of a principal, which can be used to represent any entity, such as an individual, a corporation, and a login id | java.security.Principal
|
Party |
Subject | a grouping of related information for a single entity, such as a person, including the Subject's identities as well as its security-related attributes (passwords and cryptographic keys, for example) | javax.security.auth.Subject
|
A subject can contain multiple principals and a principal represents the face of a subject. |
Authentication | authenticated principal | o.s.security.core.Authentication
|
interface Authentication extends Principal
|
GrantedAuthority | application-wide permissions granted to a principal | o.s.security.core.GrantedAuthority
|
Role |
API
Class | Source | Description | Remarks |
---|---|---|---|
Authentication | |||
UsernamePasswordAuthenticationToken | An Authentication implementation that is designed for simple presentation of a username and password | ||
TestingAuthenticationToken | An Authentication implementation that is designed for use whilst unit testing |
General
- Spring Boot Security Application (25/12/2014)
Session Management
- Control the Session with Spring Security(March 10, 2017)
Authentication
Authorization
- Expression-Based Access Control in Spring Security 4.2
- Expression-Based Access Control in Spring Security 3.1
Spring Session
- http://projects.spring.io/spring-session/
- Desc. : provides an API and implementations for managing a user’s session information
References
Spring Session 1.3.0
Spring Data
Spring Data JPA
Spring Data Redis
Spring Cloud
- Building Microservices with Spring Cloud and Docker (July 12, 2015)
misc
XML Schemas
Name | Namespace | Description | Sources |
---|---|---|---|
beans | http://www.springframework.org/schema/beans | Defines the elements to define beans. | spring-beans-4.0.xsd |
context | http://www.springframework.org/schema/context | Defines the configuration elements for the Spring Framework's application. | org.springframework.context.config |
aop | http://www.springframework.org/schema/aop | Defines the configuration elements for the Spring Framework's AOP support. | org.springframework.aop.config |
beans
- namespace :
http://www.springframework.org/schema/beans
- description : defines the elements to define beans.
- sources
- namespace :
context
- namespace :
http://www.springframework.org/schema/context
- description : defines the configuration elements for the Spring Framework's application.
- sources
- namespace :
aop
- namespace :
http://www.springframework.org/schema/aop
- description : defines the configuration elements for the Spring Framework's AOP support.
- sources
- namespace :
jdbc
- namespace :
http://www.springframework.org/schema/jdbc
- description : defines the configuration elements for the Spring Framework's embedded database support.
- sources
- namespace :
tx
- namespace : http://www.springframework.org/schema/tx
- description : defines the elements used in the Spring Framework's declarative transaction management infrastructure.
- schema : http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
mvc
- namespace : http://www.springframework.org/schema/mvc
- description
- schema : http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
util
- namespace : http://www.springframework.org/schema/util
- description
- sources
task
- namespace : http://www.springframework.org/schema/task/
- description
- schema : http://www.springframework.org/schema/task/spring-task-4.2.xsd
Samples
Common Spring Boot Application Configuration
# https://docs.spring.io/spring-boot/docs/2.1.x/reference/html/common-application-properties.html
debug: false
trace: false
logging.level:
org.springframework.boot.autoconfigure: ERROR
server.port: 8080
management.endpoints.web:
exposure.include: '*'
spring.main:
allow-bean-definition-overriding: false
spring.application..name: 'My Application'
spring.output:
ansi.enabled: always # https://docs.spring.io/spring-boot/docs/2.1.x/reference/html/boot-features-logging.html#boot-features-logging-color-coded-output
spring.security:
user:
name: boot
password: boot
Working of @Transactional
annotation according to the processing mode(proxy
or aspectj
)
Test code outline
- Annotated method is private :
private SearchRequest createAndPersistNewSearchReq()
- In-call is invoked from
testProcess
tocreateAndPersistNewSearchReq()
public class SearchTaskProcessorTest{
//...
ConfigurableApplicationContext spring;
private SearchMasterMapper masterMapper;
private SearchDetailMapper detailMapper;
private SearchRoiMapper roiMapper;
private SearchRoiParamMapper roiParamMapper;
private SearchRoiPointMapper roiPointMapper;
@BeforeClass
public void beforeClass() throws Exception{
//...
this.spring = new ClassPathXmlApplicationContext(CONFIG_LOCATION);
this.spring.registerShutdownHook();
this.masterMapper = this.spring.getBean("searchMasterMapper", SearchMasterMapper.class);
this.detailMapper = this.spring.getBean("searchDetailMapper", SearchDetailMapper.class);
this.roiMapper = this.spring.getBean("searchRoiMapper", SearchRoiMapper.class);
this.roiParamMapper = this.spring.getBean("searchRoiParamMapper", SearchRoiParamMapper.class);
this.roiPointMapper = this.spring.getBean("searchRoiPointMapper", SearchRoiPointMapper.class);
}
@AfterClass
public void afterClass(){ }
@Transactional
private SearchRequest createAndPersistNewSearchReq(){
//...
this.masterMapper.insertSearchMaster(req);
this.detailMapper.insertSearchDetail(req.getId(), cctv);
this.roiMapper.insertSearchRoi(req.getId(), cctv.getSystemId(), cctv.getId(), roi);
for(Param param: roi.getParams()){
this.roiParamMapper.insertSearchRoiParam(req.getId(), cctv.getSystemId(),
cctv.getId(), roi.getNo(), param);
}
for(Point pt: roi.getPoints()){
this.roiPointMapper.insertSearchRoiPoint(req.getId(), cctv.getSystemId(),
cctv.getId(), roi.getNo(), pt);
}
return req;
}
@Test
public void testProcess(){
SearchRequest req = this.createAndPersistNewSearchReq();
SearchTaskProcessor processor = this.spring.getBean(...);
//...
processor.process(req.getId(), "1", crtr);
}
}
In proxy mode
- Log