This project demonstrates an issue when using XML-based configuration.

If you run the main method, it will generate an UnsatisfiedDependencyException during execution.

This issue appeared in version 6.1.x. If you change the version in the pom.xml to version 6.0.x or lower, then such a problem is absent, and the code will run correctly.

To make this work in version 6.1.x, you can do the following: - remove the "name" tag from the constructor-arg for beans that use the "ref" tag. - arrange constructor-arg when forming the personBean in the order they appear in the constructor of the Person class. - use the "index" tag to specify the location of constructor-arg in the constructor of the Person class.

Likely, this is related to the removal of the LocalVariableTableParameterNameDiscoverer class in version 6.1.x. In this case, the paramNames array remains null, and as a result, the paramName variable will be initialized as an empty string.

Next, a method is called that selects an appropriate ValueHolder to populate the constructor parameter of the class.

However, during execution, there are no if blocks that take into account the aforementioned issue.

The outcome of the execution will be the generation of an exception with a message about the inability to convert types.

Comment From: snicoll

@staskorobeynikov thanks for the sample, but your project did not build cleanly for me:

[ERROR] /Users/snicoll/workspace/temp/xml_based_configuration_problem/src/main/java/com/skdev/xmlbased/MainAppXmlBased.java:9:17: '(' should be on the previous line. [MethodParamPad]
Audit done.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

I can indeed reproduce the problem by running the main class. If I switch to Spring Framework 6.0.x, this is what I get in the logs:

Mar 19, 2024 8:37:11 AM org.springframework.core.LocalVariableTableParameterNameDiscoverer inspectClass
WARNING: Using deprecated '-debug' fallback for parameter name resolution. Compile the affected code with '-parameters' instead or avoid its introspection: com.skdev.xmlbased.Country
Mar 19, 2024 8:37:11 AM org.springframework.core.LocalVariableTableParameterNameDiscoverer inspectClass
WARNING: Using deprecated '-debug' fallback for parameter name resolution. Compile the affected code with '-parameters' instead or avoid its introspection: com.skdev.xmlbased.Role
Mar 19, 2024 8:37:11 AM org.springframework.core.LocalVariableTableParameterNameDiscoverer inspectClass
WARNING: Using deprecated '-debug' fallback for parameter name resolution. Compile the affected code with '-parameters' instead or avoid its introspection: com.skdev.xmlbased.Person
bean Role method postConstruct()
Person Name = John Doe
role = ADMIN
country = United Arabian Emirates
account = User_1234
company = Amazon

Process finished with exit code 0

I guess it's one of those cases where reading the warnings makes a difference...

I've added the following to your project (as instructed by the warnings):

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.12.1</version>
    <configuration>
        <parameters>true</parameters>
    </configuration>
</plugin>

And the app starts successfully with 6.1.x:

bean Role method postConstruct()
Person Name = John Doe
role = ADMIN
country = United Arabian Emirates
account = User_1234
company = Amazon

Process finished with exit code 0

Going forward, please review (in addition to the warnings) the upgrade guide as it contains additional help.

Comment From: staskorobeynikov

Thank you for your comment. I apologize for the mistake in the project that caused it not to build. I have fixed the project and added the settings for the plugin you provided - now everything runs and works correctly.

However, if we use the plugin settings from the upgrade guide, then when running the main method, we will again encounter an exception.

Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException

This happens because by default the plugin uses version 3.1, but the -parameters flag is available only from version 3.6.2 according to the documentation.

I think you should specify in the upgrade guide that the version should be no lower than 3.6.2.

Comment From: snicoll

I think you should specify in the upgrade guide that the version should be no lower than 3.6.2.

This has been raised before and declined. I am afraid, it's not our job to document how Maven works.