- This topic has 4 replies, 3 voices, and was last updated 18 years, 4 months ago by Haris Peco.
-
AuthorPosts
-
DavidMemberHi,
I have found a curous problem with the XML editor and Spring allication context bean defition files. The example:
<beans> <bean id="factory" class="MyFactoryClass"> <constructor-arg type="java.lang.String"><value>Hello</value></constructor-arg> </bean> <bean id="myBean" class="MyBeanClass" factory-bean="factory" factory-method="create"> <constructor-arg type="int"><value>1</value></constructor-arg> </bean> </beans>
This is the standard way to invoke an instance factory method on a configured factory class, as described in the Spring documentation. However, the editor complains that there is no static “create” method on the factory class. That’s the whole point! In short, when “factory-method” is used without “factory-bean”, it must be a static method. When it is used in a bean definition which provides a reference to a factory bean instance, the method need (can) not be static.
If I simply ignore the error in the editor, I can compile and run fine. The “factory” bean and “myBean” are both created without errors and both can be retrieved from the application context. The above XML is in fact valid according to the DTD. I believe the business about checking for the existence of the method and whether it is static is an added feature in the editor. It’s nice, but only if it works. It should not report a standard Spring idiom as a critical error (not even a warning).
Is there some way I can turn this “smart” feature off, until it is fixed?
Dave
Brian FernandesModeratorDave,
Which version of ME are you using? I’m not entirely sure right now, but I think we dropped this validation rule in 5.0GA and onwards.
Best,
Brian.
DavidMemberHi again,
I am using ME 5.0.1GA. I used the manual install if that makes any difference.
Dave
DavidMemberOK, a little more weirdness. I happen to be using Spring in a console application (i.e., not a web app or web service), which is a little unusual, I suppose. Anyway, if I simply create a Java Project, and then manually add the Spring-Core libraries from the MyEclipse libraries, everything is fine in the XML editor. I can get it to use the spring-beans.dtd, and I get no errors about the non-static factory-method. If, however, I specifically use the “Add Spring capabilities…” option, I get the libraries but I DO get the error in the editor.
In either case, my sample code compiles and runs fine, with both beans being created and functioning as expected. So maybe the “Add Spring capabilites…” wizard doesn’t like being invoked on a “plain” Java application?
Anyawy, it’s a little more work to add the libraries manually, because I have to also specifiy the source and help resources, but I can live with that, and the editor seems happy with my applicationContext.xml.
Dave
Haris PecoMemberDave,
Try this
<bean id="myBean" factory-bean="factory" factory-method="create"> <constructor-arg type="int"><value>1</value></constructor-arg> </bean>
class argument is correct , but spring doesn’t use it and it isn’t necessary.
However, MyEclipse need not mark error for this and you are correct.Best
Peco -
AuthorPosts