Commit Graph

2207 Commits

Author SHA1 Message Date
Juergen Hoeller
fa168ca78a Revise FactoryBean locking behavior for strict/lenient consistency
After the bootstrap phase (and with spring.locking.strict=true during the bootstrap phase), getSingletonFactoryBeanForTypeCheck always locks. In a background bootstrap thread, it never locks. Otherwise, it tries locking and explicitly resolves the bean class for subsequent type-based resolution (even for a component-scanned class) when it fails to acquire the lock. Furthermore, getObjectFromFactoryBean follows the same locking algorithm for post-processing.

Closes gh-34902
2025-05-15 01:45:09 +02:00
Sam Brannen
03ae97b2eb Introduce Spring property for default escape character for placeholders
Spring Framework 6.2 introduced support for an escape character for
property placeholders (by default '\'). However, as of Spring Framework
6.2.6, there was no way to either escape the escape character or disable
escape character support.

For example, given a `username` property configured with the value of
`Jane.Smith` and a `DOMAIN\${username}` configuration string, property
placeholder replacement used to result in `DOMAIN\Jane.Smith` prior to
6.2 but now results in `DOMAIN${username}`. Similarly, an attempt to
escape the escape character via `DOMAIN\\${username}` results in
`DOMAIN\${username}`.

In theory, one should be able to disable use of an escape character
altogether, and that is currently possible by invoking
setEscapeCharacter(null) on AbstractPropertyResolver and
PlaceholderConfigurerSupport (the superclass of
PropertySourcesPlaceholderConfigurer).

However, in reality, there are two hurdles.

- As of 6.2.6, an invocation of setEscapeCharacter(null) on a
  PropertySourcesPlaceholderConfigurer applied to its internal
  top-level PropertySourcesPropertyResolver but not to any nested
  PropertySourcesPropertyResolver, which means that the `null` escape
  character could not be effectively applied.

- Users may not have an easy way to explicitly set the escape character
  to `null` for a PropertyResolver or
  PropertySourcesPlaceholderConfigurer. For example, Spring Boot
  auto-configures a PropertySourcesPlaceholderConfigurer with the
  default escape character enabled.

This first issue above has recently been addressed by gh-34861.

This commit therefore addresses the second issue as follows.

- To allow developers to easily revert to the pre-6.2 behavior without
  changes to code or configuration strings, this commit introduces a
  `spring.placeholder.escapeCharacter.default` property for use with
  SpringProperties which globally sets the default escape character that
  is automatically configured in AbstractPropertyResolver and
  PlaceholderConfigurerSupport.

- Setting the property to an empty string sets the default escape
  character to `null`, effectively disabling the default support for
  escape characters.

    spring.placeholder.escapeCharacter.default =

- Setting the property to any other character sets the default escape
  character to that specific character.

    spring.placeholder.escapeCharacter.default = ~

- Setting the property to a string containing more than one character
  results in an exception.

- Developers are still able to configure an explicit escape character
  in AbstractPropertyResolver and PlaceholderConfigurerSupport if they
  choose to do so.

- Third-party components that wish to rely on the same feature can
  invoke AbstractPropertyResolver.getDefaultEscapeCharacter() to obtain
  the globally configured default escape character.

See gh-9628
See gh-34315
See gh-34861
Closes gh-34865
2025-05-13 13:37:30 +02:00
Sam Brannen
e34cdc2a55 Improve Javadoc for property placeholder support 2025-05-12 17:25:49 +02:00
Sam Brannen
8b1b9ef9e5 Stop redefining placeholder syntax constants in PlaceholderConfigurerSupport 2025-05-12 17:21:37 +02:00
Sam Brannen
2b2a57b4a3 Polish Javadoc 2025-05-10 15:44:08 +02:00
Sam Brannen
bc466022b1 Fix typo in parameter name 2025-05-06 16:07:46 +02:00
Juergen Hoeller
1841ad3472 Consistently use local copy of volatile mainThreadPrefix field
Closes gh-34746
2025-04-22 12:17:03 +02:00
Sam Brannen
d0966dfb58 Revise contribution
See gh-34747
2025-04-14 14:15:50 +02:00
lituizi
bb45a3ae69 Update AbstractAutowireCapableBeanFactory.ignoreDependencyInterface() Javadoc
Specifically, the documentation update reflects that:

- Initially, it was mentioned that only the `BeanFactoryAware`
  interface is ignored by default.

- The updated documentation now correctly states that `BeanNameAware`,
  `BeanFactoryAware`, and `BeanClassLoaderAware` interfaces are all
  ignored by default.

This change ensures a more accurate representation of the default
behavior regarding which dependency interfaces are automatically
ignored during autowiring in the context of Spring's bean factory
mechanism.

Closes gh-34747

Signed-off-by: lituizi <2811328244@qq.com>
2025-04-14 14:07:35 +02:00
Sam Brannen
a22d204681 Remove duplicate words in Java source code
Discovered using regular expression: \b(\w+)\s+\1\b[^(}]
2025-04-14 11:24:55 +02:00
Juergen Hoeller
c4f66b776f Use single volatile field for indicating pre-instantiation phase
See gh-34729
2025-04-12 06:00:18 +02:00
Juergen Hoeller
6ea9f66fd7 Remove superfluous DefaultParameterNameDiscoverer configuration 2025-04-10 18:33:39 +02:00
Juergen Hoeller
eea6addd26 Avoid lenient locking for additional external bootstrap threads
Includes spring.locking.strict revision to differentiate between true, false, not set.
Includes checkFlag accessor on SpringProperties, also used in StatementCreatorUtils.

Closes gh-34729
See gh-34303
2025-04-10 18:33:21 +02:00
Juergen Hoeller
74ab5e4e25 Enforce circular reference exception between more than two threads as well
See gh-34672
2025-04-07 22:37:19 +02:00
Juergen Hoeller
463541967a Enforce circular reference exception between all thread variations
Closes gh-34672
2025-04-07 17:08:47 +02:00
Sam Brannen
dbd47ff4f9 Implement additional micro performance optimizations
See gh-34717
2025-04-04 15:51:37 +02:00
Sam Brannen
381bc4c405 Polish contribution
See gh-34717
2025-04-04 15:29:10 +02:00
Olivier Bourgain
0f2308e85f Implement micro performance optimizations
- ClassUtils.isAssignable(): Avoid Map lookup when the type is not a
  primitive.

- AnnotationsScanner: Perform low cost array length check before String
  comparisons.

- BeanFactoryUtils: Use char comparison instead of String comparison.
  The bean factory prefix is '&', so we can use a char comparison
  instead of more heavyweight String.startsWith("&").

- AbstractBeanFactory.getMergedBeanDefinition(): Perform the low cost
  check first. Map lookup, while cheap, is still more expensive than
  instanceof.

Closes gh-34717

Signed-off-by: Olivier Bourgain <olivierbourgain02@gmail.com>
2025-04-04 14:34:55 +02:00
Juergen Hoeller
e7db15b325 Perform type check before singleton check for early FactoryBean matching
Closes gh-34710
2025-04-03 11:59:22 +02:00
Juergen Hoeller
203ca30a64 Include cause in MethodInvocationException message
Closes gh-34691
2025-04-01 22:12:17 +02:00
Juergen Hoeller
34ea0461c7 Polishing 2025-04-01 22:12:09 +02:00
Juergen Hoeller
743f32675d Only attempt load for CGLIB classes in AOT mode
Closes gh-34677
2025-03-31 16:39:18 +02:00
Juergen Hoeller
3ddc607b3e Add spring.locking.strict property to common appendix
See gh-34303
2025-03-31 16:38:28 +02:00
Juergen Hoeller
75e5a75da5 Enforce circular reference exception within non-managed thread
Closes gh-34672
2025-03-28 20:46:09 +01:00
Juergen Hoeller
9bf01df230 Evaluate lenientLockingAllowed flag per DefaultListableBeanFactory instance
See gh-34303
2025-03-28 20:45:06 +01:00
Stéphane Nicoll
2862c87601 Make sure the generated values are available from a static context
This commit updates the tests of property values code generated to
invoke the generated code from a `static` context. This ensures that
the test fails if that's not the case.

This commit also updated LinkedHashMap handling that did suffer from
that problem.

Closes gh-34659
2025-03-27 12:06:18 +01:00
Juergen Hoeller
aa56b5001a Detect late-set primary markers for autowiring shortcut algorithm
Closes gh-34658
2025-03-26 23:47:42 +01:00
Juergen Hoeller
6905dff660 Introduce spring.locking.strict=true flag for 6.1.x style bean creation locking
Closes gh-34303
2025-03-25 17:08:55 +01:00
Juergen Hoeller
37fb79e8ff Fix qualifier resolution for aliased name against parent factory
Closes gh-34644
2025-03-25 00:08:42 +01:00
Juergen Hoeller
dc41ff569e Add javadoc notes on potential exception suppression in getBeansOfType
Closes gh-34629
2025-03-21 15:52:42 +01:00
Juergen Hoeller
47651350f3 Polishing 2025-03-21 10:58:40 +01:00
Sam Brannen
208d52d852 Introduce Checkstyle rule for separator symbol location 2025-03-19 15:35:44 +01:00
Juergen Hoeller
ad949a7450 Add includeNonSingletons flag for ObjectProvider stream access
Closes gh-34591
2025-03-18 16:10:30 +01:00
Juergen Hoeller
911cdb2ad0 Add resolveAutowireCandidates variant with includeNonSingletons and allowEagerInit
Closes gh-34591
2025-03-13 18:48:43 +01:00
Juergen Hoeller
143985e862 Add tests for primary/fallback/defaultCandidate precedence
Closes gh-34449
2025-03-08 12:22:14 +01:00
Juergen Hoeller
4bd280b87e Explain availability and uniqueness (including primary/fallback/default) in javadoc
Closes gh-34447
2025-03-08 12:22:04 +01:00
Juergen Hoeller
f3b50c9a58 Ignore null beans in SimpleAutowireCandidateResolver.resolveAutowireCandidates
Closes gh-34543
2025-03-05 22:44:09 +01:00
Juergen Hoeller
403362fe3c Polishing 2025-03-04 18:44:56 +01:00
Juergen Hoeller
d2733cea36 Notify lenientCreationFinished condition after locked creation as well
Closes gh-34522
2025-03-01 22:20:23 +01:00
Juergen Hoeller
e230ea537c Consistently resolve unique default candidate bean
Closes gh-34432
2025-02-18 13:11:36 +01:00
Juergen Hoeller
94eb6006e8 Leniently accept same singleton instance if implicitly appeared
Closes gh-34427
2025-02-18 13:01:08 +01:00
Juergen Hoeller
dfc10c1a8d Wait for lenient bean creation in non-locked threads as well
Closes gh-34349
2025-02-12 23:06:22 +01:00
Juergen Hoeller
b336bbe539 Wait for lenient bean creation in locked thread when necessary
Closes gh-34349
2025-02-12 12:17:02 +01:00
Juergen Hoeller
ace2f0a3e5 Expose resolveAutowireCandidates method with basic candidate filtering
DependencyObjectProvider is aligned to check basic autowire-candidate status even in case of custom filtering.

Closes gh-34203
2025-02-07 19:00:25 +01:00
Stéphane Nicoll
ec037b1ec0 Polish "Add support for multidimensional arrays"
See gh-34183
2025-02-05 14:35:33 +01:00
xumengqi
68c1e2ac92 Add support for multidimensional arrays
See gh-34183
2025-02-05 14:23:09 +01:00
Juergen Hoeller
cda7e98643 Lazily override default editors when actually needed
Closes gh-34361
2025-02-04 13:26:16 +01:00
Juergen Hoeller
8c2b44bd6c Support filtered/unfiltered stream access on ObjectProvider
Closes gh-34318
Closes gh-34203
2025-02-03 15:04:27 +01:00
Juergen Hoeller
323e52b5a9 Continue with pre-instantiation when current bean is in creation already
Closes gh-34349
2025-01-31 15:16:52 +01:00
Sam Brannen
53afe27109 Clean up warnings in Gradle build
See gh-34332
2025-01-29 17:52:27 +01:00