Tagged: constructor, spring, validation
- This topic has 3 replies, 2 voices, and was last updated 7 years, 5 months ago by
support-tony.
-
AuthorPosts
-
The Spring bean validation rule for constructor arguments erroneously validates abstract bean definitions.
Reproduce:
1. Create a new Java project with any Java runtime.
2. Add Spring facet, I tried this both with Spring facet versions 3.0, 3.1 and 4.1. A default project is sufficient.
3. Add the following bean definitions into the applicationContext.xml or whatever you named the application context file (obviously correct the schema version to match your facet version for having a pristine test, although it matters not):<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd"> <!-- This is an abstract bean, the constructor argument count validator should not report a problem, but it does --> <bean id="abstractParent" class="java.util.Date" abstract="true"> <constructor-arg index="0" value="1" /> <constructor-arg index="1" value="1" /> </bean> <bean id="concreteBean" parent="abstractParent"> <constructor-arg index="2" value="1" /> </bean> </beans>
4. Save the file.
Now Spring validation is going to complain about the abstractParent bean having no 2-arg constructor, even though its bean definition is abstract and it should not validate abstract bean definitions.
The concreteBean bean correctly will not have a problem since it has a 3rd constructor argument and a 3-argument constructor does exist.
-
This topic was modified 7 years, 6 months ago by
Robert Varga.
-
This topic was modified 7 years, 6 months ago by
Robert Varga.
support-tonyKeymasterRobert,
Thanks for the steps to reproduce the problem. I have raised a fault report for development to investigate.
Does this false validation error affect any other functions that you’re using?
To eliminate this false validation, you can turn off constructor argument validation. Go to Window->Preferences->Validation->Spring, open the Beans Validator node and turn off the Bean Constructor Argument Rule option, then click OK. This can also be done on a per-project basis.
We’ll let you know when there is a fix for this.
Hi Tony,
I don’t think it affects any other functions, it is simply that the validator does not skip abstract beans.
I raised the same issue in the Spring Tool Suite issue tracker, too:
https://issuetracker.springsource.com/browse/STS-4435
Unfortunately the suggested workaround disables this rule altogether so in order to eliminate false positives, it also eliminates valid positives (complaining about non-abstract beans not having constructors of the specified argument number).
support-tonyKeymasterRobert,
Thanks for raising the bug with STS. As some of the tools in our Spring support is based on STS, it may take a fix from those guys to fix it in MyEclipse though we may be able to fix this ourselves.
You’re right that the workaround isn’t an acceptable workaround but, as far as I can tell, it’s the only way to avoid the spurious validation message. Fortunately, the problem doesn’t affect other functions but I can appreciate that it is annoying and confusing. Hopefully, we can do something about this before too long.
Sorry, again, for the problem.
-
This topic was modified 7 years, 6 months ago by
-
AuthorPosts