IDEA allows to declare a Groovy class as a Spring bean by <bean>, is a bug?

I'm new with Spring and Groovy so I'm not sure it is allowable or not. I create LimeImpl, a Groovy class. This class implements a Java interface, Lime. IDEA allows me to declare a Spring bean as below

        
    

    
]]>


without any error or warning message.

Is it acceptable? Or is a IDEA's bug?

'Cause AFAIK, I need to declare the Spring bean which is written in Groovy like this

]]>

0
6 comments

Hello t800t8,

What does the bean source code look like?

-tt


0
Avatar
Permanently deleted user

Here it is (looks like a Java class)

0
Avatar
Permanently deleted user

Both are perfectly legal, but have different semantics. Since Groovy code just compiles to Java bytecode, there's no reason that this

won't work, assuming you compile the Groovy first. After all, Spring has no way of knowing whether the class file was created from Java, Groovy, Scala, JRuby, or any other language. OTOH, this ]]>

works even if you don't compile the Groovy class, since it can invoke the Groovy classloader, which can in turn invoke the Groovy compiler. There's even an optional tag to periodically check to see if your Groovy bean has changed, and recompile/reload the bean.

--Dave Griffith

0
Avatar
Permanently deleted user

Clear! Thanks a lot, Dave :)

0
Avatar
Permanently deleted user

This actually points out an interesting and tricky issue with JetGroovy, in that in some cases Groovy files are meant to be compiled, and in some cases they are meant to simply be copied as resources. IDEA (and by extension JetGroovy) doesn't have any way of distinguishing these cases. Perhaps the "exclude from compile" semantics needs to be expanded a bit, so that we can have directories excluded from compilation which are nonetheless copied as resources.

--Dave Griffith

0
Avatar
Permanently deleted user

Good point. However before IDEA team opens the API for this, it seems we can go off with JetGroovy option to toggle compilation of groovy files.

0

Please sign in to leave a comment.