- Replace synchronized with Lock when guarding long-running operations
- Remove unnecessary synchronization in FileSystemWatcher
- Replace HashMap with ConcurrentHashMap in Restarter
- Remove unnecessary locking on AtomicBoolean in
SpringApplicationBuilder
- Remove unnecessary locking in SimpleFormatter
Closes gh-36670
The SimpleAsyncTaskExecutorBuilder can be used to create
SimpleAsyncTaskExecutor. It will be auto-configured into the context.
SimpleAsyncTaskExecutorCustomizer can be used to customize the built
SimpleAsyncTaskExecutor.
If virtual threads are enabled:
- SimpleAsyncTaskExecutor will use virtual threads
- SimpleAsyncTaskExecutorBuilder will be used as the application task
executor
A new property 'spring.task.execution.simple.concurrency-limit' has been
added to control the concurrency limit of the SimpleAsyncTaskExecutor
Closes gh-35711
The new ConnectionFactoryDecorator can be used to decorate the
ConnectionFactory built by the ConnectionFactoryBuilder.
The new R2dbcObservationAutoConfiguration configures a
ConnectionFactoryDecorator to attach a ObservationProxyExecutionListener
to ConnectionFactories. This enables Micrometer Observations for R2DBC
queries.
Closes gh-33768
When there is an existing value, deducing the bind method may
incorrectly result in the use of constructor binding. This
results in a failure in the configuration properties
post-processor as it refuses to bind properties to a bean whose
attributes indicate that constructor binding should have been used.
This commit updates ConfigurationPropertiesBean to avoid tryin to
deduce the bind method and instead use the presence or absence of an
existing value to determine the type of binding that should be used.
Only when there is no existing value is constructor binding
appropriate.
Fixes gh-36175
Previously, with the converter beans in a conversion service that
appears after the bean factory's conversion service, they would not
be called for a conversion that could be handled by the
ObjectToObjectConverter in the bean factory's conversion service.
This commit creates a new FormattingConversionService that is empty
except for the converter beans and places it first in the list.
It's followed by the bean factory's conversion service. The shared
application conversion service is added to the end of the list to
pick up any conversions that the previous two services could not
handle. This should maintain backwards compatibility with the
previous arrangement where the converter beans were added to an
application conversion service that went after the bean factory's
conversion service.
Fixes gh-34631
Previously, when a Servlet-based WebServer was stopped it would also
stop the ServletContext. This led to problems as Tomcat and Undertow
would then not allow a restart. Jetty would allow a restart but
duplicate servlet registrations would then be attempted.
This commit modifies the WebServer lifecycle to separate stopping
and destruction for both servlet and reactive web servers. This
allows a WebServer's stop() implementation to leave some components
running so that they can be restarted. To completely shut down a
WebServer destroy() must now be called.
Both Tomcat and Jetty WebServers have been updated to stop their
network connections when stop() is called but leave other components
running. This works with both servlet and reactive web servers.
Note that an Undertow-based Servlet web server does not support
stop and restart. Once stopped, a Servlet Deployment cannot be
restarted and it does not appear to be possible to separate the
lifecycle of its network connections and a Servlet deployment.
Reactor Netty and Undertow-based reactive web servers can now also
be stopped and then restarted. Calling stop() stops the whole server
but this does not cause a problem as there's no (application-exposed)
ServletContext involved. There may be room to optimize this in the
future if the need arises.
Closes gh-34955
Update Logback and Log4J2 so that they include the application name on
each log line. If `spring.application.name` had not been set, or if
`logging.include-application-name` is `false` then the name is not
logged.
Closes gh-35593
Add support for logging correlation IDs with Logback or Log4J2 whenever
Micrometer tracing is being used.
The `LoggingSystemProperties` class now accepts a defualt value resolver
which will be used whenever a value isn't in the environment. The
`AbstractLoggingSystem` provides a resolver that supports the
`logging.pattern.correlation` property and will return a value whenever
`LoggingSystem.EXPECT_CORRELATION_ID_PROPERTY` is set.
Using `LoggingSystem.EXPECT_CORRELATION_ID_PROPERTY` allows us to
provide a consistent width for the correlation ID, even when it's
missing from the MDC.
The exact correlation pattern returned will depend on the `LoggingSytem`
implementation. Currently Logback and Log4J2 are supported and both
make use of a custom converter which delegates to a new
`CorrelationIdFormatter` class.
Closes gh-33280
Previously, when using SpringApplication.from() any additional
sources configured using with() would be applied to every
SpringApplication that was created within the scope of the call to
run(). This caused problems with Spring Cloud's bootstrap context
where the additional sources would be applied to both the user's
application and to the boostrap context's application.
This commit updates the hook that's used to apply the additional
sources so that it's only applied once. This results in the
additional sources only being added to the first SpringApplication
that is run.
Closes gh-35873
Support custom Log4J2 log levels by changing `LoggerConfiguration` so
that it can now report levels using a `LevelConfiguration` object
rather than the limited `LogLevel` enum.
The `Log4J2LoggingSystem` class now uses `LevelConfiguration.ofCustom`
for custom logging levels, rather than throwing an exception.
The `LoggersEndpoint` has also been updated so that it can return the
custom logger name.
Fixes gh-35227
Properties `ssl.bundle.pem.mybundle.keystore.private-key-password`
and `ssl.bundle.pem.mybundle.truststore.private-key-password` have
been added for configuring the password required to decrypt an
encrypted private key.
Only PKCS8 private keys with encryption are supported. PKCS1 and EC
private keys with encryption are much more complex to decrypt, and
are not supported.
Fixes gh-35652
Update `SpringApplicationExtensions.kt` with `fromApplication` and
`with` functions that make `SpringApplication.from(...)` easier to use
with Kotlin.
Fixes gh-35756
Previously, if a `@ConfigurationProperties`-annotated `@Bean` method
returned a type that looked like it could be constructor bound, the
registered runtime hints were incorrect. With only the bean's class
to work with, the hints registrar would incorrectly determine that
the type would be constructor bound and would not register the hints
required for Java bean binding.
This commit updates the registrar to allow the caller to provide a
Bindable which knows both what should be bound and how it should be
bound, thereby allowing the registrar to generate the correct hints.
The tests for the AOT processor have also been updated to remove
duplication of the tests in BindableRuntimeHintsRegistrarTests and
to focus on the contribution creating Bindable instances with the
bind method that is required to produce the correct reflection hints.
Closes gh-35564
Co-authored-by: Phillip Webb <pwebb@vmware.com>
There were several tests in CPBFIAPT that were duplicating tests in
BindableRuntimeHintsRegistrarTests. To test the AOT processor, all
that is really necessary is to assert that the expected types are
found and passed to BindableRuntimeHintsRegistrar. The tests for
BindableRuntimeHintsRegistrar are then responsible for asserting
that the expected hints are generated for the various different
types.
Closes gh-35645
Update `SpringApplication.run` to that it returns a wrapper which
provides access to the `ApplicationContext` rather than the
`ApplicationContext` directly.
This should provide a natural place to add more accessors in the future
should we need to.
Closes gh-35451
This commit returns the running application context when running an
application via SpringApplication#from so that it is consistent with
the regular SpringApplication#run.
Closes gh-35203
Update `SslOptions` so that `null` is used for default values rather
than empty sets. Most libraries use `null` to indicate defaults so
aligning our class makes things easier.
See gh-34814
Update Tomcat, Jetty, Undertow and Netty servers so that an SslBundle
is used to apply SSL configuration. Existing `Ssl` properties are
internally adapted to an `SslBundle` using the `WebServerSslBundle`
class. Additionally, if `Ssl.getBundle()` returns a non-null value the
the `SslBundles` bean will be used to find a registered bundle by name.
See gh-34814
Add classes to support SSL bundles which can be used to apply SSL
settings in a centralized way. An `SslBundle` can be registered with
an `SslBundleRegistry` and obtained from an `SslBundles` instance. The
`DefaultSslBundleRegistry` provides a default in-memory implementation.
Different client libraries often configure SSL in slightly different
ways. To accommodate this, the `SslBundle` provides a layered approach
of obtaining SSL information:
- `getStores` provides access to the key store and trust stores
as well as any required key store password.
- `getManagers` provides access to the `KeyManagerFactory`,
`TrustManagerFactory` as well as the `KeyManger` and
`TrustManager` arrays that they create.
- `createSslContext` provides a convenient way to obtain a new
`SSLContext` instance.
In addition, the `SslBundle` also provides details about the key being
used, the protocol to use and any options that should be applied to the
SSL engine.
See gh-34814
This reverts commit 25e8f2d575, reversing
changes made to e5bc9a2fcb.
Unfortunately, upon additional review we realised that these changes
should not have been accepted. They're a partial implementation of
support for programmatically configuring Logback, implemented in a way
that only works during AOT processing and also potentially makes it
harder for us to implement full support in the future.
Closes gh-34361
This commit includes a change to stop using an API in Logback that
has been deprecated without replacement. As Logback now only supports
.xml configuration files, it would only ever have thrown an
exception. The call to the API has been replaced with thrown an
exception directly.
Closes gh-34686
This commit includes a change to stop using an API in Logback that
has been deprecated without replacement. As Logback now only supports
.xml configuration files, it would only ever have thrown an
exception. The call to the API has been replaced with thrown an
exception directly.
Closes gh-34670
Update `StandardConfigDataResource` so that the underlying file is
considered in equals/hashcode. Prior to this commit, if the classpath
included `.` then the same resource could be loaded twice. Once via
a `ClassPathResource` and once via a `FileSystemResource`.
Fixes gh-34212
If the name is set, it is used. If not, the bean name is used. If that's
not set, the convention based name is taken.
Registration failures now throw an IllegalStateException instead of
being logged. DynamicRegistrationBean.setIgnoreRegistrationFailure
can be used to restore the old behavior.
See gh-33911
Remove instance suppliers in bean definitions and depend instead
on reflection. This allows the AOT engine to correctly process
the definitions.
Fixes gh-33763
Update `DefaultBindConstructorProvider` so that deduced constructors
are not used if there is an existing value.
Prior to this commit, constructor detection logic was not compatible
with earlier versions of Spring Boot. With Spring Boot 3.0.1, given
a class of the following form:
@ConfigurationProperties(prefix = "example")
public class ExampleProperties {
@NestedConfigurationProperty
private final NestedProperty nested = new NestedProperty(
"Default", "default");
public NestedProperty getNested() {
return nested;
}
}
If `NestedProperty` has a single constructor with arguments, constructor
binding would be used. In Spring Boot 2.x, setter injection would have
been used.
The updated code now only uses constructor injection if an explicit
`@ConstructorBinding` annotation is present, or if there is no existing
value.
Fixes gh-33409
See gh-33710
Update `DefaultBindConstructorProvider` so that it no longer detects
constructors when the `Bindable` has an existing value. This update
allows us change `ConfigurationPropertiesBindingPostProcessor` and
related classes so that all instances created from `@Bean` methods
are treated as `JAVA_BEAN` bindings and will not be accidentally
re-created using constructor binding.
Fixes gh-33710
Add `SpringProfileIfNestedWithinSecondPhaseElementSanityChecker` which
will provide a warning if `<springProfile>` is used within a phase 2
model element. This is similar to Logback's own `<if>` warnings.
The `LogbackLoggingSystem` has also been updated so that warning are
printed when present.
Fixes gh-33610
Switch `model.markAsSkipped` to `model.deepMarkAsSkipped` in
`SpringProfileModelHandler`.
Although the current call doesn't appear to be causing issues,
it seems best to align our <springProfile> support with the way
that Logback implements its own `<if>` support.
Closes gh-33618
Prior to this change, when using spring-boot-starter-logging, JBoss
Logging would route like this:
JBoss Logging -> Log4j2 API -> SLF4J -> Logback
This is inefficient as there's no need for it to go via the Log4j2
API.
This commit updates the Logback logging system to configure a system
property that controls JBoss's routing. With this change in place,
JBoss Logging will route like this:
JBoss Logging -> SLF4J -> Logback
Closes gh-33155
Update `@Autowired` detection logic to consider all constructors and to
search user classes.
Fixes gh-33061
Co-authored-by: Phillip Webb <pwebb@vmware.com>
In Tomcat 10.0, reflection hints on Http11AprProtocol were
registering hints on AbstractProtocol as a side effect.
Tomcat 10.1 removed this protocol and related hints, breaking
Http11NioProtocol usage in Spring Boot.
This commit contributes reflection hints for protocol properties
accessed reflectively from org.apache.catalina.connector.Connector.
See gh-33064
Reorder `SpringBootJoranConfigurator.addModelHandlerAssociations` so
that handlers are added before calling the super method. Prior to this
commit, handlers were added behind filters which prevented them from
being used in `<if>` blocks.
Fixes gh-33028
Commit 29f085bd1a690ff7281e00b3a925e1160850ffbb in Spring Framework
automatically registers hints for enclosing directories. This fixes the
tests to use a contains instead of exact match.
Commit 29f085bd1a690ff7281e00b3a925e1160850ffbb in Spring Framework
automatically registers hints for enclosing directories. This fixes the
tests to expect hints for those directories as well.