Previously, when defining a package for a class, LaunchedURLClassLoader
would use the manifest from the first location that contained the
required package. If the package was split across multiple locations,
this could lead to the manifest from a jar other than the one that
contains the class being used.
This commit updates LaunchedURLClassLoader so that it will use the
manifest of the jar file that contains the class which triggered the
definition of the package.
Closes gh-5485
LaunchedURLClassLoader preemptively defines the package for any
classes that it attempts to load so that the manifest from a nested
jar is correctly associated with the package. This can lead to a race
where the package is defined on two threads in parallel, resulting
in an IllegalArgumentException being thrown.
This problem was manifesting itself as a NoClassDefFoundError.
If the initialization of a class failed due to the above-described
IllegalArgumentException, subsequent attempts to use that class
would then fail with a NoClassDefFoundError.
This commit updates LaunchedURLClassLoader to catch the
IllegalArgumentException and then double-check that the package has
already been defined. This approach, including thrown an
AssertionError when the second check fails, is modelled on the
approach taken by URLClassLoader.
Closes gh-5464
The commit adds a new BuildInfo task that can be used to generate
a build.properties file, intended for inclusion in the Actuator's
info endpoint.
A default instance of the task can be configure using the plugin's
DSL:
springBoot {
buildInfo()
}
Additional properties can also be configured using the DSL:
springBoot {
buildInfo {
additionalProperties = [
'foo': 'bar'
]
}
}
When configured via the DSL, the Java plugin's classes task is
configured to depend on the build info task. Alternatively, if more
control is required, the task can be declared and configured manually:
task buildInfo(type: org.springframework.boot.gradle.buildinfo.BuildInfo) {
additionalProperties = [
'foo': 'bar'
]
}
classes {
dependsOn buildInfo
}
See gh-2559
Add @PropertyMapping annotation which can be used to mark annotation
attributes that should contribute Environment properties.
Provides a quick way for tests to change auto-configuration behavior in
a structured way.
Fixes gh-4901
Provide a way for full auto-configuration to be disabled
programmatically. Primarily added to allow special test annotations to
take over partial auto-configuration but still load
@SpringBootApplication classes.
See gh-4901
Remove the need for a nested @Configuration class when writing a test
that need to @Import configuration.
Primarily added to allow @ImportAutoConfiguration to be used directly
on test classes.
Fixes gh-5473
Add a ContextCustomizerFactory to provide TestRestTemplate as a bean for
tests annotated with WebIntegrationTests. Additionally provide support
for automatically expanding URLs of the form `/example` to
`http://localhost:${local.server.port}/example`.
Fixes gh-5227
Provide variants of `WebClient` and `WebConnectionHtmlUnitDriver` that
automatically resolve relative URLs to "localhost:${local.server.port}".
Fixes gh-5472
Add a `@MockBean` annotation which can be used to setup and inject mocks
into an application context. The annotation can be used on test classes,
test fields, configuration classes or configuration fields. When used on
a field the annotation also acts as an injection point.
Fixes gh-5042
Update @IntegrationTest to use @BootstrapWith rather than an explicitly
defined set of test execution listeners.
Also introduce a new @SpringApplicationTest annotation that is similar
to @SpringApplicationConfiguration but a bootstrapper.
Fixes gh-5230
Allow detection of `@SpringBootConfiguration` classes for both standard
spring tests and bootstrap (@IntegrationTest @WebIntegrationTest) based
tests.
Closes gh-5295
Add TestTypeExcludeFilter which will automatically attempt to exclude
test only configurations. All `@Configuration` annotated inner-classes
of tests are automatically excluded. The `@TestConfiguration` annotation
can be used to explicitly if a configuration needs explicit exclusion.
See gh-5295
See gh-4901
Add a new TypeFilter specifically for excluding candidate components.
The filter is applied to `@SpringBootApplication` and allows tests to
dynamically contribute exclude filters so that specific classes of
component can be excluded.
See gh-5295
See gh-4901
Add a new @SpringBootConfiguration annotation that can be used to
indicate the primary application configuration. The new annotation is
primarily indented to allow test automatically code to find the main
configuration class.
See gh-5295
Update `@EnableTransactionManagement` so that `proxyTargetClass` is
set to true. This ensures that @Transactional beans that aren't
interface based can still be proxied.
Fixes gh-5423
This is a follow-on from the work done in 5009933. Now that SPR-14015
has been fixed, constructor injection can also be used for parameterised
dependencies, including optional dependencies that are injected via
an ObjectProvider.
Closes gh-5306
Spring Boot does not support Thymeleaf 3 yet. This commit prevents the
auto-configuration to activate if Thymeleaf 3 is available on the
classpath.
Closes gh-5371