Update the ContextIdApplicationContextInitializer default NAME_PATTERN
to favor the developer defined `${spring.application.name}` value over
the deployer defined `${vcap.application.name}`.
Fixes gh-4926
Update TomcatEmbeddedServletContainerFactory so that logic to disable
persistent sessions happens after Tomcat's standard Manager creation
logic.
Fixes gh-4543
If application context refresh fails, SpringApplication will have a
null context. Previously, this would result in an NPE when looking for
an ExitCodeExceptionMapper.
This commit updates SpringApplication to gracefully handle the context
being null when looking for an ExitCodeExceptionMapper.
Closes gh-4803
This commit makes sure to also include any `GenericConverter` flagged for
inclusion in the conversion service to use to convert configuration keys.
Previously, those were ignored as `Converter` and `GenericConverter` are
two separate interfaces.
Closes gh-4988
EmbeddedVelocityToolboxView is used with both embedded containers and
when a Spring Boot application is deployed to a servlet container. It
process the ServletContext to intercept calls to getResource so that it
can load Velocity’s toolbox.xml file from within an executable jar.
Previously, when it created the proxy, it didn’t specify the ClassLoader
to use. This resulted in the proxy being created using the ClassLoader
that loaded the Class that is being proxied. This fails when the
application is deployed to a ServletContainer as the ClassLoader that
loaded the ServletContext implementation is the container’s ClassLoader
and it cannot see the classes that are specific to the web application.
This commit updates EmbeddedVelocityToolboxView to specify the
ClassLoader to use when creating the proxy. It specifies its own
ClassLoader thereby ensuring that the proxy creation can load
application-specific classes.
Fixes gh-4967
Prior to Tomcat 8.0.30, its default behaviour was for the mapper to
redirect a request for context-root to context-root/. This redirection
was switched off by default in 8.0.30 by default. This has proven
to be problematic and Tomcat 8.0.31 will reinstate the old default.
While we are waiting for Tomcat 8.0.31 to be released, this commit
explicitly sets the default back to what it was in 8.0.29 and earlier
and what it will be in 8.0.31.
Closes gh-4937
This commit completes the changes to consistently used static final
fields for Log instances that were started in ec2f33f9. Specifically it:
- Removes this. when accessing logger fields that are now static
- Renames some fields from log to logger
- Makes some logger fields static
See gh-4784
Update exit code support to allow the ExitCodeGenerator interface to
be placed on an Exception. Any uncaught exception implementing the
interface and returning a non `0` status will now trigger a System.exit
with the code.
Fixes gh-4803
In Spring Boot 1.3.1 the class 'org.apache.logging.log4j.LogManager'
is used to check which logging backend is in use. But this class is
part of the log4j-api.jar and not part of the log4j-core.jar.
That means the check is invalid, as it does not detect the actual
core implementation of Log4j2 correctly.
When you want to redirect Log4j2 logging via SLF4J, a NPE occurs
each time the application is reloaded by the devtools, because the
class Log4j2RestartListener tries to shutdown Log4j2 resources.
This is done by accessing some internal shutdown method via
reflection. The method that is being looked for does not exist
when the log4j-api.jar is available only on the classpath,
resulting in a NPE. This causes the application to stop,
disappearing from the Spring Boot Dashboard in Eclipse
Closes gh-4831
Previously, the worker used non-daemon threads which meant that they
prevented the JVM from shutting down. Ideally, we’d avoid this problem
by closing the worker and access log receiver as part of stopping
Undertow, however, due to an apparent bug in Undertow [1], it’s not
possible to do so cleanly.
This commit configures the access log worker to use daemon threads so
that they do not prevent the JVM from shutting down. Unfortunately,
this means that the threads will still be running after the context has
been closed but before the JVM shuts down but that appears to be
unavoidable due to the aforementioned Undertow bug.
Closes gh-4793
[1] https://issues.jboss.org/browse/UNDERTOW-597
Ensure that Collections.isEmpty() is used to check if there are no
elements in a collections. This is more explicit and can be faster than
calling .size().
Closes gh-4783
If the user provides their own ServerProperties bean we want to peek
at it to see if they set the port (and only that) when we are deciding
if the actuator context needs to be created. This happens very early
(in a @Condition) so we need to be very defensive. There are already
quite a few checks in place to prevent a ServerProperties bean from
being instantiated unless we really need it, and yet, when it is
we can do more.
This change creates the bean (and the ManagementProperties) in a
throwaway BeanFactory using the same BeanDefinition as the main
context. This ensures that when the main context bean is created
it will be in the "natural" order and binding to the Environment
can take place as normal.
Fixes gh-4631
Change SpringApplication exception handling to log details before calling
the SpringApplicationRunListeners. Prior to this commit it wasn't possible
for a listener to shutdown logging.
Fixes gh-4680
Closes gh-4686
Update `UndertowEmbeddedServletContainerFactory` so that the canonical
path is used when setting up the document root. Prior to this commit
Windows machines with `java.io.tmpdir` set to a tilde-compressed path
would cause problems.
Fixes gh-4765
Closes gh-4766
- Consistent error handling applied to BasicJsonParser,
GsonJsonParser, JsonSimpleJsonParser and YamlJsonParser
- Add tests in AbstractJsonParserTests to verify consistency
- Rename tests for JsonSimpleJsonParser to match the name of the
class under test.
Closes gh-4690
Previously, when ignoreUnknownFields was false and property names were
being filtered based on whether or not they begin with the target name,
relaxed variants of the target name were not considered. This resulted
in different delimiters resulting in a non-match. For example, the
property ENV_FOO_NAME would be filtered out when the target name
was env.foo.
This commit updates PropertiesConfigurationFactory to pass all of the
relaxed variants for the target name to the matcher. For the example
above one of those variants will be env_foo which matches ENV_FOO_NAME
due to the matching delimiter.
PropertiesConfigurationFactory was already creating a RelaxedNames
instance for the target name. The code has been reworked a little to
allow these relaxed names to be reused, thereby avoiding the cost of
computing all of the relaxed variants of the target name a second time.
Closes gh-4775
Ensure that gzip compression is applied when the `Content-Length` header
is not specified. Prior to this commit Tomcat and Jetty would compress a
response that didn't contain the header, but Undertow would not.
Fixes gh-4769
Add a `server.server-header` property which can be used to override the
`server` header usually sent back automatically by Tomcat/Jetty or
Undertow.
See https://www.owasp.org/index.php/Securing_tomcat for background.
Fixes gh-4461
Closes gh-4504
Update RandomValuePropertySource to protect against the random source
returning Long.MIN_VALUE. In such cases the sign bit can't be unset and
prior to this commit the random value stayed negative.
Closes gh-4672
Refine the validator memory optimization so that only directly created
validators are nulled out. Also update the logic to ensure that
`destroy` is also called.
See gh-4734
This is an optimization that recognizes the need for Hibernate
validator to cache reflection data, but also that we don't need it
after the bulk of the work has been done on context refresh.
Fixes gh-4734
Tomcat 8.0.30 has changed to using relative URIs in its redirects
by default. To avoid any problems that this behaviour change may
causes we override the default and configure Tomcat to continue to
use absolute URIs.
Closes gh-4715
Previously, LoggingApplicationListener would clean up the logging
system in response to any application context with which it was
registered being closed. This caused problems when a child context was
closed. Specifically, closing the child context would cause any
SLF4J-based logging systems to unregister the JUL bridge handler
preventing an JUL logging being bridged into Logback or Log4J2.
This commit updates LoggingApplicationListener so that the logging
system is only cleaned up when a root application context is
closed.
Closes gh-4651
Previously, the test that verified that Undertow's access log could be
enabled and was written to the correct file expected the log to be
available as soon as the request to the server had completed. Undertow
writes the access log asynchronously so the test failed intermittently
due to a race between the access log being written and the test
asserting that it exists.
This commit updates the test to wait for up to 10 seconds for the
access log to be available.
See gh-4670
Undertow 1.3.2 changed the default access log file suffix from '.log'
to just 'log'. Thus we need to adapt the file name pattern to include
the missing dot.
Closes gh-4670
This commit introduces a new property, application.title, that can
be used in a banner. Its value is resolved from the application
manifest's Implementation-Title attribute.
Closes gh-4603
Previously, ConfigFileApplicationListener would always add itself to the
end of the list of environment post processors loaded via
spring.factories. This meant that its order (highest precedence + 10)
would not be honoured and it would only be in the right place in the
list if any other post processors happened to have a higher precedence.
This commit updates ConfigFileApplicationListener to sort the list of
post processors using AnnotationAwareOrderComparator once its added
itself to the list.
Closes gh-4595
Previously, EmbeddedWebApplicationContext used synchronized, but did
not do so consistently. It also synchronized on this so its lock was
exposed outside of the class, creating a risk of deadlock if a caller
synchronized incorrectly. Furthermore, not all fields on the class
were sychronized so the class wasn't truly thread-safe.
This commit attempts to rectify some of the problems above. The use
of synchronized has been dropped in favour of using a volatile field
for the embedded servlet container. Whenever this field is accessed,
a local variable is used to "cache" the value thereby preventing a
change on another thread from causing unwanted behaviour such as an
NPE.
Closes gh-4593
Remove 3.4.1 logger workaround (adding package to default service). See
CORE-2436 on the liquibase tracker for more details.
Closes gh-4591
Closes gh-4625
Since the `LoggingSystem` may be retrieved very early during the context
initialization, we should do a lookup by name even if only one instance
of that bean is ultimately expected in the context.
The constant defining the bean name is now public to ease that use case.
Closes gh-4584
Fixed initially in #3725
The target attribute is effectively checked for null beforehand so this
additional defensive check can be removed.
Closes gh-4567
Previously, UndertowEmbeddedServletContainerFactory always used
Undertow’s default ServletContainer. This meant that if there were two
UndertowEmbeddedServletContainers created, they would share the same
ServletContainer and the second one that was created would overwrite
the deployment for the first. This resulted in a async request
handling failing as the attempt to look up the deployment for the
first embedded Undertow instance would incorrectly find the deployment
for the second.
This commit fixes the problem by ensuring that each
UndertowEmbeddedServletContainerFactory uses a separate Undertow
ServletContainer instance.
Closes gh-4329
Previously springProfile supported multi profiles separated by comma but
it doesn´t work if there are whitespaces. Now, springProfile will read
values cleaning whitespaces.
See gh-4445
Update SpringApplication so that startup exceptions are only logged
once. A custom UncaughtExceptionHandler is now used when running in
the main thread to suppress errors that have already been logged.
Fixes gh-4423