@ -29,7 +29,6 @@ list]. Questions on the Framework itself should be asked on StackOverflow
@@ -29,7 +29,6 @@ list]. Questions on the Framework itself should be asked on StackOverflow
[[overview-getting-started-with-spring]]
== Getting Started with Spring
This reference guide provides detailed information about the Spring Framework.
@ -64,10 +63,9 @@ Examples of how you, as an application developer, can benefit from the Spring pl
@@ -64,10 +63,9 @@ Examples of how you, as an application developer, can benefit from the Spring pl
* Make a Java method execute in a database transaction without having to deal with
transaction APIs.
* Make a local Java method a remote procedure without having to deal with remote APIs.
* Make a local Java method a management operation without having to deal with JMX APIs.
* Make a local Java method a message handler without having to deal with JMS APIs.
* Make a local Java method an HTTP endpoint without having to deal with the Servlet API.
* Make a local Java method a message handler without having to deal with the JMS API.
* Make a local Java method a management operation without having to deal with the JMX API.
The Spring Framework consists of features organized into about 20 modules. These modules
are grouped into Core Container, Data Access/Integration, Web, AOP (Aspect Oriented
Programming), Instrumentation, Messaging, and Test, as shown in the following diagram.
@ -148,7 +145,6 @@ into a Spring application context for caching (EhCache, Guava, JCache), mailing
@@ -148,7 +145,6 @@ into a Spring application context for caching (EhCache, Guava, JCache), mailing
(JavaMail), scheduling (CommonJ, Quartz) and template engines (FreeMarker, JasperReports,
Velocity).
The `spring-expression` module provides a powerful <<expressions,__Expression
Language__>> for querying and manipulating an object graph at runtime. It is an extension
of the unified expression language (unified EL) as specified in the JSP 2.1
The `spring-webmvc-portlet` module (also known as the __Web-Portlet__ module) provides
the MVC implementation to be used in a Portlet environment and mirrors the functionality
of the `spring-webmvc` module.
of the Servlet-based `spring-webmvc` module.
[[overview-testing]]
@ -293,7 +289,6 @@ stateless session beans for use in scalable, fail-safe web applications that mig
@@ -293,7 +289,6 @@ stateless session beans for use in scalable, fail-safe web applications that mig
declarative security.
[[dependency-management]]
==== Dependency Management and Naming Conventions
Dependency management and dependency injection are different things. To get those nice
@ -336,9 +331,8 @@ So the first thing you need to decide is how to manage your dependencies: we gen
@@ -336,9 +331,8 @@ So the first thing you need to decide is how to manage your dependencies: we gen
recommend the use of an automated system like Maven, Gradle or Ivy, but you can also do
it manually by downloading all the jars yourself.
You will find bellow the list of Spring artifacts. For a more complete description of each
modules, see <<overview-modules>>.
Below you will find the list of Spring artifacts. For a more complete description of
each module, see <<overview-modules>>.
.Spring Framework Artifacts
|===
@ -386,7 +380,7 @@ modules, see <<overview-modules>>.
@@ -386,7 +380,7 @@ modules, see <<overview-modules>>.
|org.springframework
|spring-jms
|JMS support package, including helper classes to send and receive JMS messages
|JMS support package, including helper classes to send/receive JMS messages
|org.springframework
|spring-messaging
@ -410,11 +404,11 @@ modules, see <<overview-modules>>.
@@ -410,11 +404,11 @@ modules, see <<overview-modules>>.
|org.springframework
|spring-web
|Web support packages, including client and web remoting
|Foundational web support, including web client and web-based remoting
|org.springframework
|spring-webmvc
|REST Web Services and model-view-controller implementation for web applications
|HTTP-based Model-View-Controller and REST endpoints for Servlet stacks
|org.springframework
|spring-webmvc-portlet
@ -422,11 +416,9 @@ modules, see <<overview-modules>>.
@@ -422,11 +416,9 @@ modules, see <<overview-modules>>.
|org.springframework
|spring-websocket
|WebSocket and SockJS implementations, including STOMP support
|WebSocket and SockJS infrastructure, including STOMP messaging support
|===
[[overview-spring-dependencies]]
===== Spring Dependencies and Depending on Spring
Although Spring provides integration and support for a huge range of enterprise and
@ -442,7 +434,6 @@ anything is unclear, refer to the documentation of your dependency management sy
@@ -442,7 +434,6 @@ anything is unclear, refer to the documentation of your dependency management sy
look at some sample code - Spring itself uses Gradle to manage dependencies when it is
building, and our samples mostly use Gradle or Maven.
[[overview-maven-dependency-management]]
===== Maven Dependency Management
If you are using http://maven.apache.org/[Maven] for dependency management you don't even
@ -511,7 +502,6 @@ And for snapshots:
@@ -511,7 +502,6 @@ And for snapshots:
</repositories>
----
[[overview-maven-bom]]
===== Maven "Bill Of Materials" Dependency =====
It is possible to accidentally mix different versions of Spring JARs when using Maven.
@ -558,7 +548,6 @@ attribute when depending on Spring Framework artifacts:
@@ -558,7 +548,6 @@ attribute when depending on Spring Framework artifacts:
<dependencies>
----
[[overview-gradle-dependency-management]]
===== Gradle Dependency Management
To use the Spring repository with the http://www.gradle.org/[Gradle] build system,
If you prefer to use http://ant.apache.org/ivy[Ivy] to manage dependencies then there
@ -618,7 +606,6 @@ Once configured, you can add dependencies in the usual way. For example (in `ivy
@@ -618,7 +606,6 @@ Once configured, you can add dependencies in the usual way. For example (in `ivy
Although using a build system that supports dependency management is the recommended
@ -636,7 +623,6 @@ for http://repo.spring.io/milestone/org/springframework/spring[milestones] and
@@ -636,7 +623,6 @@ for http://repo.spring.io/milestone/org/springframework/spring[milestones] and
Logging is a very important dependency for Spring because __a)__ it is the only mandatory
@ -654,9 +640,8 @@ logging library: migration is easy because backwards compatibility is preserved
@@ -654,9 +640,8 @@ logging library: migration is easy because backwards compatibility is preserved
with applications that extend Spring. The way we do this is to make one of the modules
in Spring depend explicitly on `commons-logging` (the canonical implementation of JCL),
and then make all the other modules depend on that at compile time. If you are using
Maven for example, and wondering where you picked up the dependency on
`commons-logging`, then it is from Spring and specifically from the central module
called `spring-core`.
Maven for example, and wondering where you picked up the dependency on `commons-logging`,
then it is from Spring and specifically from the central module called `spring-core`.
The nice thing about `commons-logging` is that you don't need anything else to make your
application work. It has a runtime discovery algorithm that looks for other logging
@ -666,136 +651,22 @@ you get pretty nice looking logs just from the JDK (java.util.logging or JUL for
@@ -666,136 +651,22 @@ you get pretty nice looking logs just from the JDK (java.util.logging or JUL for
You should find that your Spring application works and logs happily to the console out
of the box in most situations, and that's important.
[[overview-not-using-commons-logging]]
===== Not Using Commons Logging
Unfortunately, the runtime discovery algorithm in `commons-logging`, while convenient
for the end-user, is problematic. If we could turn back the clock and start Spring now
as a new project it would use a different logging dependency. The first choice would
probably be the Simple Logging Facade for Java ( http://www.slf4j.org[SLF4J]), which is
also used by a lot of other tools that people use with Spring inside their applications.
There are basically two ways to switch off `commons-logging`:
. Exclude the dependency from the `spring-core` module (as it is the only module that
explicitly depends on `commons-logging`)
. Depend on a special `commons-logging` dependency that replaces the library with
formats]). For Maven users, the minimal dependencies needed are:
[source,xml,indent=0]
[subs="verbatim,quotes,attributes"]
----
@ -841,17 +711,18 @@ formats]). For Maven users, the minimal dependencies needed are:
@@ -841,17 +711,18 @@ formats]). For Maven users, the minimal dependencies needed are:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>2.7</version>
<version>2.6.2</version>
</dependency>
</dependencies>
----
If you also wish to use SLF4J, the following dependencies are also needed:
If you also wish to enable SLF4J to delegate to Log4j, e.g. for other libraries
which use SLF4J by default, the following dependency is also needed:
[source,xml,indent=0]
[subs="verbatim,quotes,attributes"]
@ -860,7 +731,7 @@ If you also wish to use SLF4J, the following dependencies are also needed:
@@ -860,7 +731,7 @@ If you also wish to use SLF4J, the following dependencies are also needed:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.7</version>
<version>2.6.2</version>
</dependency>
</dependencies>
----
@ -886,25 +757,143 @@ Here is an example `log4j2.xml` for logging to the console:
@@ -886,25 +757,143 @@ Here is an example `log4j2.xml` for logging to the console:
</Configuration>
----
[[overview-native-jcl]]
====== Runtime Containers with Native JCL
Many people run their Spring applications in a container that itself provides an
implementation of JCL. IBM Websphere Application Server (WAS) is the archetype. This
often causes problems, and unfortunately there is no silver bullet solution; simply
excluding `commons-logging` from your application is not enough in most situations.
[[overview-avoiding-commons-logging]]
===== Avoiding Commons Logging
Unfortunately, the runtime discovery algorithm in the standard `commons-logging` API,
while convenient for the end-user, can be problematic. If you'd like to avoid JCL's
standard lookup, there are basically two ways to switch it off:
To be clear about this: the problems reported are usually not with JCL per se, or even
with `commons-logging`: rather they are to do with binding `commons-logging` to another
framework (often Log4j). This can fail because `commons-logging` changed the way they do
the runtime discovery in between the older versions (1.0) found in some containers and
the modern versions that most people use now (1.1). Spring does not use any unusual
parts of the JCL API, so nothing breaks there, but as soon as Spring or your application
tries to do any logging you can find that the bindings to Log4j are not working.
. Exclude the dependency from the `spring-core` module (as it is the only module that
explicitly depends on `commons-logging`)
. Depend on a special `commons-logging` dependency that replaces the library with