Commit Graph

2447 Commits

Author SHA1 Message Date
Marc Wrobel c48c5e7691 Fix and improve Javadoc in spring-context
Closes gh-28802
2022-07-13 14:45:23 +02:00
Stephane Nicoll 2c92d7da8f Harmonize RuntimeHintsRegistrar implementations
Closes gh-28801
2022-07-12 18:30:23 +02:00
Stephane Nicoll 54a3f66d1d Move RuntimeHints predicate support to a dedicated package
This commit moves `RuntimeHintsPredicate` and its support classes that
form a cohesive concept in a dedicated `.predicate` package.

Closes gh-28799
2022-07-12 16:16:12 +02:00
Sam Brannen 65f9106d49 Polishing 2022-07-11 18:53:29 +02:00
Sam Brannen dad67423d6 Suppress warnings 2022-07-11 18:53:11 +02:00
Sam Brannen 5178e9c28e Simplify hint registration for Spring AOP proxies
Prior to this commit, when users wished to register proxy hints for a
Spring AOP JDK dynamic proxy, they were required to explicitly specify
SpringProxy, Advised, and DecoratingProxy along with user interfaces.

This commit simplifies hint registration for Spring AOP proxies by
introducing two completeJdkProxyInterfaces() methods in AopProxyUtils,
one that accepts strings and one that accepts classes that represent
the user-specified interfaces implemented the user component to be
proxied. The SpringProxy, Advised, and DecoratingProxy interfaces are
appended to the user-specified interfaces and returned as the complete
set of interfaces that the proxy will implement.

Closes gh-28745
2022-07-10 20:10:12 +02:00
Sam Brannen 2af08cf163 Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/test/java/org/springframework/core/annotation/TypeMappedAnnotationTests.java
#	spring-test/src/test/java/org/springframework/test/context/junit4/TimedSpringRunnerTests.java
#	spring-test/src/test/java/org/springframework/test/util/MetaAnnotationUtilsTests.java
#	spring-test/src/test/java/org/springframework/test/util/OverriddenMetaAnnotationAttributesTests.java
2022-07-09 16:24:04 +02:00
Sam Brannen d274e893a6 Remove superfluous static declaration for enum, annotation, & interface 2022-07-09 16:16:13 +02:00
Sam Brannen 73d92d66b9 Stop using convention-based annotation attribute overrides in tests
This commit replaces convention-based annotation attribute overrides in
tests with explicit use of @AliasFor -- except for tests in spring-core,
since we still want to test our support for convention-based annotation
attribute overrides.

See gh-28760
2022-07-08 19:28:14 +02:00
Arjen Poutsma 9b739a2310 Update scheduling package to use java.time
This commit deprecates all methods in org.springframework.scheduling
that use

- Date, in favor of variants that take an Instant.
- long & TimeUnit, in favor of variants that take a Duration.

Closes: gh-28714
2022-07-08 16:25:27 +02:00
Sébastien Deleuze fd265a18c6 Add runtime hints for scheduling support
Closes gh-28696
2022-07-04 14:18:27 +02:00
Sam Brannen ce5076ffe8 Merge branch '5.3.x' 2022-07-03 18:05:36 +02:00
Sam Brannen d1d6eb095e Fix GenericApplicationContextTests on Microsoft Windows (round 2)
The previous change to the tests resulted in a failure on Windows when
using the DefaultResourceLoader by expecting an exception when no
exception is thrown.

This commit narrows the scope of the if-clause to expect an exception
only when using the FileSystemResourceLoader on Windows.

See gh-28703, gh-28746
2022-07-03 17:59:37 +02:00
Sam Brannen 94e3738a94 Merge branch '5.3.x'
# Conflicts:
#	spring-context/src/test/java/org/springframework/context/support/GenericApplicationContextTests.java
2022-07-03 14:51:37 +02:00
Sam Brannen e608b36713 Improve GenericApplicationContextTests.getResource*() tests
This commit updates the tests so that they test something meaningful on
MS Windows as well as on Linux/Mac.

See gh-28703, gh-28746
2022-07-03 14:36:41 +02:00
jason 59180e76a7 Fix GenericApplicationContextTests on Microsoft Windows
The tests introduced in commit 9868c28c73 pass on Mac OS and Linux but
fail on Microsoft Windows.

This commit updates the tests so that they pass on MS Windows as well.

See gh-28703
Closes gh-28746
2022-07-03 14:35:07 +02:00
Sam Brannen b2998842af Merge branch '5.3.x' 2022-07-02 17:09:29 +02:00
Sam Brannen c5987d7c37 Fix typo in test 2022-07-02 17:09:07 +02:00
Sébastien Deleuze 8c063a0e2a Add runtime hints for MethodValidationPostProcessor
Closes gh-28689
2022-07-01 10:18:08 +02:00
Brian Clozel 772d801e48 Test the ApplicationContextAotGenerator with the agent
This commit adds new tests for the `ApplicationContextAotGenerator`,
this time leveraging the `RuntimeHintsAgent` that checks the need for
runtime hints at runtime.

See gh-27981
2022-06-30 18:20:32 +02:00
Sébastien Deleuze 9135921d1d Move BindingReflectionHintsRegistrar to spring-context
Closes gh-28735
2022-06-30 11:56:08 +02:00
Sam Brannen af16e49334 Merge branch '5.3.x'
# Conflicts:
#	spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java
#	spring-context/src/test/java/org/springframework/context/support/GenericApplicationContextTests.java
2022-06-27 18:14:00 +02:00
Sam Brannen 9868c28c73 Honor ProtocolResolvers in GenericApplicationContext
When the ProtocolResolver SPI was introduced in Spring Framework 4.3,
support for protocol resolvers was added in DefaultResourceLoader's
getResource() implementation; however, GenericApplicationContext's
overridden getResource() implementation was not updated accordingly.

Prior to this commit, if a GenericApplicationContext was configured
with a custom ResourceLoader, registered protocol resolvers were
ignored.

This commit ensures that protocol resolvers are honored in
GenericApplicationContext even if a custom ResourceLoader is used.

Closes gh-28703
2022-06-27 18:00:29 +02:00
Sam Brannen a970516080 Polish GenericApplicationContextTests 2022-06-27 17:05:02 +02:00
Sam Brannen 5e5e95aff7 Polish RuntimeHintsUtils 2022-06-27 16:29:34 +02:00
Stephane Nicoll 6199835d6e Harmonize generated class name conventions
This commit moves the responsibility of naming classes to the
GenerationContext. This was already largely the case before, except that
the concept of a "mainTarget" and "featureNamePrefix" was specific
to bean factory initialization contributors.

ClassNameGenerator should now be instantiated with a default target
and an optional feature name prefix. As a result, it does no longer
generate class names in the "__" package.

GeneratedClasses can now provide a new, unique, GeneratedClass or
offer a container for retrieving the same GeneratedClass based on an
identifier. This lets all contributors use this facility rather than
creating JavaFile manually. This also means that ClassNameGenerator
is no longer exposed.

Because the naming conventions are now part of the GenerationContext, it
is required to be able to retrieve a specialized version of it if a
code generation round needs to use different naming conventions. A new
withName method has been added to that effect.

Closes gh-28585
2022-06-23 16:05:23 +02:00
Sam Brannen a3d3667e64 Merge branch '5.3.x' 2022-06-21 16:19:21 +02:00
Sam Brannen 26df4580b3 Revise internals of LoggingCacheErrorHandler
Since LoggingCacheErrorHandler was only recently introduced in 5.3.16,
we have decided to completely revise its internals (protected API) in
5.3.x while retaining the current public API.

Specifically, this commit:

- introduces protected getLogger() and isLogStackTraces() methods to
  improve extensibility

- revises logCacheError() to accept a Supplier<String> for lazy
  resolution of error messages

Closes gh-28672
See gh-28670, gh-28648
2022-06-21 16:13:55 +02:00
Sam Brannen 6152e41249 Merge branch '5.3.x' 2022-06-21 14:41:24 +02:00
Vedran Pavic 57208bf47a Simplify LoggingCacheErrorHandlerTests
See gh-28648
2022-06-21 14:40:09 +02:00
Sam Brannen 22bfd5a7b6 Merge branch '5.3.x' 2022-06-21 14:14:53 +02:00
Sam Brannen 8b34558284 Polish LoggingCacheErrorHandler 2022-06-21 14:07:39 +02:00
Vedran Pavic dbe8f200a9 Simplify creation of LoggingCacheErrorHandler with logged stacktrace
At present, creating a LoggingCacheErrorHandler that logs stack traces
also requires supplying the logger to be used. This might be
inconvenient for some users, as it requires usage of the Commons
Logging API.

This commit simplifies creation of such as LoggingCacheErrorHandler
instance by adding a constructor that only accepts a boolean flag
indicating whether to log stack traces.

Closes gh-28670
2022-06-21 13:50:10 +02:00
Stephane Nicoll 90759fb38f Relocate duplicated mock implementations to test fixtures
Closes gh-28659
2022-06-20 08:55:52 +02:00
Johnny Lim 5ae3902d71 Guard logging in RuntimeHintsBeanFactoryInitializationAotProcessor
See gh-28658
2022-06-20 07:58:47 +02:00
Juergen Hoeller a14650e0dc findAnnotationOnBean only falls back to bean class in case of no factory method
Most importantly, static @Bean methods do not expose their @Configuration class-level annotations anymore, aligned with the behavior for non-static @Bean methods.

Closes gh-28298
2022-06-14 14:01:38 +02:00
Juergen Hoeller 4e1b9f1492 Replace deep exception message nesting with custom inclusion of cause messages
Includes deprecation of NestedServletException, whereas NestedCheckedException and NestedRuntimeException remain as base classes with several convenience methods.

Closes gh-25162
2022-06-14 14:00:28 +02:00
Sébastien Deleuze 12d756a252 Refine ReflectiveProcessorBeanRegistrationAotProcessor
Add support for processing implemented interfaces and
remove Reflective from runtime hints.

See gh-28518
2022-06-13 14:54:57 +02:00
Brian Clozel 9c9b2356ce Add RuntimeHints predicates generator
The `RuntimeHints` API allows to describe hints for the reflection,
proxies and resources behavior at runtime. The need for a particular
behavior can be covered by several types of hints, at different levels.
This knowledge can be important in several cases:

* before contributing additional hints, infrastructure can check if an
  existing hint already covers the behavior
* this can be used in test suites and test infrastructure

This commit adds a new RuntimeHintsPredicates that generates `Predicate`
instances for testing `RuntimeHints` against a desired runtime behavior
for reflection, resources or proxies.

Closes gh-28555
2022-06-10 18:55:14 +02:00
Stephane Nicoll 363722893b Make sure RuntimeHintsRegistrar are invoked only once
Close gh-28594
2022-06-09 15:02:32 +02:00
Sam Brannen 282c3bc952 Merge branch '5.3.x' 2022-06-08 16:40:23 +02:00
Sam Brannen 8478e8e70a Polish contribution
This commit:

- fixes Checkstyle violations
- improves Javadoc
- adds missing @since tags
- renames getCurrentQueueSize() to getQueueSize()
- avoids NullPointerExceptions in getQueueSize()
- introduces tests for queue size and queue capacity

Closes gh-28583
2022-06-08 16:39:10 +02:00
Rémy e386bdb82c Expose ThreadPoolTaskExecutor queue size and capacity for metrics
We use Grafana to monitor our app via Spring's JMX exporter, and we
think it could be interesting to have at least the current queue size
for this purpose since the queue size directly affects the app memory
load. Having the queue capacity seems also interesting to set up
triggers whose values are calculated based on the maximum capacity of
the queue.

This commit introduces new getCurrentQueueSize() and getQueueCapacity()
methods in ThreadPoolTaskExecutor.

See gh-28583
2022-06-08 16:39:00 +02:00
Stephane Nicoll 571543285a Polish 2022-06-08 14:08:16 +02:00
Phillip Webb 172102d225 Refine ApplicationContextAotGenerator class name generation
Refine the class name logic so that the name is passed in rather
than using `ApplicationContext.getId()`. Also propagate the name
so that the generated classes use it.

See gh-28565
2022-06-04 12:26:00 -07:00
Phillip Webb 4bd33cb6e0 Allow ApplicationContextAotGenerator to generated better class names
Update `ApplicationContextAotGenerator` so that it can generate class
names based on a `target` class and using the ID of the application
context. Prior to this commit, the generated class name was always
`__.BeanFactoryRegistrations`.

Closes gh-28565
2022-06-03 18:15:37 -07:00
Sam Brannen 73acab7635 Merge branch '5.3.x'
# Conflicts:
#	spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContextUtils.java
2022-06-03 13:35:22 +02:00
Sam Brannen aab9da0366 Polish LocaleResolver support 2022-06-03 13:10:55 +02:00
Stephane Nicoll baebf71ed7 Polish "Improve AssertJ usage in cache config tests"
See gh-28559
2022-06-03 10:33:01 +02:00
Andreas Grub 5ed0c848fe Improve AssertJ usage in cache config tests
See gh-28559
2022-06-03 10:15:36 +02:00
Stephane Nicoll da8c4de263 Add AotDetector to reliably opt-in for optimizations
This commit adds a central utility to figure out if the application
must run with Ahead-Of-Time optimizations. This is mandatory for running
in a native image but can be selected on the JVM using the
"spring.aot.enabled" property.

This commit also introduces a utility that can be used to initialize a
context with generated artifacts. This represents the runtime
counterpart of ApplicationContextAotGenerator.

Closes gh-28474
2022-06-02 14:52:11 +02:00
Brian Clozel 8af1496b37 Expand hints conditions support in RuntimeHints
Prior to this commit, the hints conditions were only supported for the
`TypeHint` case. GraalVM generally expanded this concept to all hints
and we should do the same.

Right now, only the `typeReachable` condition is available but we should
design for possible future additions.

This commit introduces a new `ConditionalHint` contract implemented by
all hints compatible with this approach. The condition information is
also used in all configuration writers as a result.

Closes gh-28126
2022-06-02 11:35:03 +02:00
Sam Brannen bc3b3d01ee Polishing 2022-06-01 14:57:16 +02:00
Sam Brannen 279f9647ab Merge branch '5.3.x' 2022-05-31 16:14:16 +02:00
Sam Brannen aa8802a81d Avoid new AssertJ deprecations 2022-05-31 16:13:31 +02:00
Sam Brannen ee209de9cf Merge branch '5.3.x'
# Conflicts:
#	spring-beans/src/test/java/org/springframework/beans/factory/support/security/CallbacksSecurityTests.java
#	spring-context/src/test/java/org/springframework/ejb/access/LocalSlsbInvokerInterceptorTests.java
#	spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteSlsbInvokerInterceptorTests.java
#	spring-web/src/test/java/org/springframework/remoting/jaxws/JaxWsSupportTests.java
#	spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolutionIntegrationTests.java
2022-05-31 14:15:36 +02:00
Sam Brannen 1beb7068f6 Use new AssertJ exception assertions 2022-05-31 14:08:28 +02:00
Sam Brannen 720261db26 Use List.of() and Set.of() where feasible 2022-05-30 18:42:48 +02:00
Phillip Webb efa8ffb728 Polish 2022-05-26 20:56:06 -07:00
Stephane Nicoll 059b66bf26 Register annotation based on its type
This commit improves registerAnnotation to use the annotation type
rather than a `MergedAnnotation` attribute.

See gh-28497
2022-05-25 10:30:43 +02:00
Stephane Nicoll d0afbe40e6 Tag EventListener as a reflective operation
This commit adds compatibility of declarative event listeners in a
native image.

See gh-28475
2022-05-20 15:14:59 +02:00
Stephane Nicoll 4cca190aad Add support of declarative use of reflection
This commit adds a `@Reflective` annotation that can be used to declare
that the annotated element requires reflection at runtime. By default,
the annotated element is exposed but this can be customized by
specifying a dedicated `ReflectiveProcessor`.

Closes gh-28469
2022-05-20 15:02:46 +02:00
Stephane Nicoll 9487e8ce1e Polish 2022-05-18 13:57:48 +02:00
Sam Brannen 70415b1781 Merge branch '5.3.x' 2022-05-17 15:41:08 +02:00
Sam Brannen 59c7bb1f86 Use Arrays.toString instead of Arrays.asList when generating Strings 2022-05-17 15:36:31 +02:00
Sam Brannen 874077d16e Apply "advanced" instanceof pattern matching 2022-05-17 11:24:32 +02:00
Sam Brannen bf8a54decf Switch focus to JUnit Jupiter in testing examples 2022-05-16 10:05:37 +02:00
Sam Brannen 3d39dfc4ce Polishing 2022-05-14 18:35:58 +02:00
Sam Brannen 754636ee56 Merge branch '5.3.x' 2022-05-14 18:32:14 +02:00
Sam Brannen f2fe7f335c Improve nullReturningBeanPostProcessor() test
See gh-28459
2022-05-14 18:30:39 +02:00
evgeny.bovykin 7cb6ac0a02 Make inner classes static when feasible (on main)
A static nested class does not keep an implicit reference to its
enclosing instance.

This prevents a common cause of memory leaks and uses less memory per
instance of the class.

Closes gh-28433
2022-05-10 11:45:18 +02:00
Sam Brannen 5f8a4bcdc5 Merge branch '5.3.x'
# Conflicts:
#	spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java
#	spring-context/src/main/java/org/springframework/scripting/support/StandardScriptFactory.java
2022-05-09 20:08:37 +02:00
Sam Brannen e26d8839b3 Stop referring to features as Java 6/7 features where unnecessary 2022-05-09 19:09:06 +02:00
Juergen Hoeller 2b65f274dc Use Set.of instead of HashSet with Arrays.asList 2022-05-06 16:19:27 +02:00
Juergen Hoeller f8c4071f73 Introduce removeApplicationListener method at ApplicationContext level
Closes gh-14023
2022-05-06 16:14:04 +02:00
Phillip Webb 16e7f1f212 Complete refactor of AOT concepts
Remove the AOT code that now has an alternative API.

Closes gh-28414
2022-05-05 13:34:52 -07:00
Phillip Webb 702207d9ee Add updated ApplicationContextAotGenerator
Add `ApplicationContextAotGenerator` implementation that makes
use of the new AOT generation APIs.

See gh-28414
2022-05-05 13:25:37 -07:00
Phillip Webb e4a8258fb2 Update ConfigurationClassPostProcessor AOT support
Update `ConfigurationClassPostProcessor` so that it provides AOT
contributions via the `BeanFactoryInitializationAotProcessor`
interface.

See gh-28414
2022-05-05 13:25:36 -07:00
Phillip Webb ddba45d01d Polish formatting 2022-05-05 12:35:21 -07:00
Juergen Hoeller 0f6d459de7 Support for jakarta.enterprise.concurrent.Asynchronous annotation
Closes gh-28400
2022-05-05 17:25:39 +02:00
Stephane Nicoll 7820804bf6 Allow registration of bean factory contributors via spring.factories
Closes gh-28342
2022-04-14 15:11:48 +02:00
Stephane Nicoll 8b97c2dc9d Polish 2022-04-14 14:56:08 +02:00
Brian Clozel 38019d2249 Allow static registration of RuntimeHints
Prior to this commit, we could only contribute `RuntimeHints` through
two mechanisms:
* `AotContributingBeanFactoryPostProcessor`, consdering the entire
  `BeanFactory` and designed for contributing both code and hints.
* `AotContributingBeanPostProcessor`, consdering beans one by one, but
  also designed for contributing both code and hints.

There are cases where libraries and applications want to contribute
`RuntimeHints` only, in a more static fashion: a dependency being
present, or a piece of infrastructure being considered by the
application context are good enough signals to contribute hints about
resources or reflection.

This commit adds the `RuntimeHintsRegistrar` contract for these cases.
Implementations can be declared as `spring.factories` and they will be
processed as soon as they're detected on the classpath. They can also be
declared with `@ImportRuntimeHints` and they will be processed if the
annotated bean definition is considered in the application context.
This annotation should be mainly used on configuration classes and on
bean methods.

```
@Configuration
@ImportRuntimeHints(CustomRuntimeHintsRegistrar.class)
public class MyConfiguration {

  @Bean
  @ImportRuntimeHints(OtherRuntimeHintsRegistrar.class)
  public MyBean myBean() {
    //...
  }
}
```

Closes gh-28160
2022-04-14 13:06:43 +02:00
Sam Brannen 1574fed90b Merge branch '5.3.x' 2022-04-13 10:08:31 +02:00
Sam Brannen a7cf19cec5 Improve documentation and matching algorithm in data binders 2022-04-13 09:55:40 +02:00
Sam Brannen c9e7816762 Merge branch '5.3.x' 2022-04-09 10:43:02 +02:00
Sam Brannen 6fad00ed22 Ensure dynamic proxy with AOP introduction includes lambda interfaces
Closes gh-28209
2022-04-09 09:57:43 +02:00
Juergen Hoeller 9ae35e78b1 Merge branch '5.3.x'
# Conflicts:
#	spring-context-support/src/test/java/org/springframework/validation/beanvalidation2/ValidatorFactoryTests.java
#	spring-context/src/test/java/org/springframework/validation/beanvalidation/ValidatorFactoryTests.java
#	spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpRequest.java
2022-04-08 14:42:12 +02:00
Juergen Hoeller 35de7e19ee Introduce initializer callback for Bean Validation Configuration
Closes gh-27956
2022-04-08 14:39:36 +02:00
Juergen Hoeller 10e979e58b Polishing 2022-04-08 14:37:41 +02:00
Juergen Hoeller 7e1782ea22 Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	spring-core/src/main/java/org/springframework/core/convert/Property.java
2022-04-08 13:10:34 +02:00
Juergen Hoeller 4143b445d6 Polishing 2022-04-08 13:04:14 +02:00
Juergen Hoeller 12d8010395 Merge branch '5.3.x' 2022-03-25 18:08:55 +01:00
Juergen Hoeller 35610a535d Expose cancel(mayInterruptIfRunning) variant in ScheduledTask
Closes gh-28233
2022-03-25 18:06:31 +01:00
Sam Brannen d11389e783 Merge branch '5.3.x' 2022-03-21 17:13:30 +01:00
Sam Brannen 8fc744f4f4 Improve Javadoc for BeanExpressionResolver 2022-03-21 16:57:27 +01:00
Sam Brannen 3da7a48a17 Explicitly close ApplicationContexts and clean up warnings in tests 2022-03-20 13:19:25 +01:00
Sam Brannen 7f4e09e994 Merge branch '5.3.x'
# Conflicts:
#	spring-context/src/test/java/org/springframework/context/event/PayloadApplicationEventTests.java
#	spring-context/src/test/java/org/springframework/context/groovy/GroovyApplicationContextTests.java
#	spring-context/src/test/java/org/springframework/format/datetime/joda/DateTimeFormatterFactoryBeanTests.java
#	spring-context/src/test/java/org/springframework/format/datetime/joda/DateTimeFormatterFactoryTests.java
#	spring-context/src/test/java/org/springframework/format/datetime/joda/JodaTimeFormattingTests.java
#	spring-context/src/test/java/org/springframework/format/support/FormattingConversionServiceTests.java
#	spring-context/src/test/java/org/springframework/remoting/rmi/RmiSupportTests.java
#	spring-context/src/test/java/org/springframework/scripting/support/StandardScriptFactoryTests.java
#	spring-web/src/test/java/org/springframework/remoting/caucho/CauchoRemotingTests.java
#	spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpComponentsHttpInvokerRequestExecutorTests.java
2022-03-20 12:55:39 +01:00
Sam Brannen 9a5891e6e6 Explicitly close ApplicationContexts and clean up warnings in tests
This commit also ensures that various test methods actually test
something now.
2022-03-20 12:34:56 +01:00
Stephane Nicoll 0cbea29517 Polish 2022-03-18 18:25:30 +01:00