| Author |
Beans from resources.groovy not beging picked up by DI
|
Paras Jain
Ranch Hand
Joined: Feb 26, 2005
Posts: 137
|
|
Hi,
In order to define my beans using Spring DSL, I have moved my bean definitions from resources.xml to resources.groovy. After doing so my beans are not automatically injected to my controllers and services. Previously, with resources.xml, without explicitly wiring the beans if I define something like
in the controllers or services code, myBeanName would be automatically injected. But this is not happening now.
Is there any other configuration or setting we have to do in addition to just moving the definitions from resources.xml to resources.groovy
The beans in .groovy are being initiated and loaded by the container, because if I make any mistake in the definition, it complains. The only thing is that the beans are not being injected to controllers.
Regards,
Paras
|
Paras Jain
SCJP 5.0
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15229
|
|
|
Are these beans classes you've pulled in to your grails app via a JAR file or possibly sitting under you src/java folder? Or are they groovy classes. If they are groovy classes, where do they reside?
|
 |
Paras Jain
Ranch Hand
Joined: Feb 26, 2005
Posts: 137
|
|
Thanks for the reply Gregg,
Most of these are Java classes pulled from one of the jar.
|
 |
Peter Ledbrook
author
Greenhorn
Joined: Jul 15, 2009
Posts: 25
|
|
|
What does your resources.groovy file look like?
|
 |
Paras Jain
Ranch Hand
Joined: Feb 26, 2005
Posts: 137
|
|
Hi Peter,
Thanks for the reply. It is working now. Actually one of the bean which had backslashes \ was not working. I kept that one in resources.xml and moved everything else to resources.groovy.
The culprit bean looks like this
I tried to escape the backslashes with \\ but it was not working. So I left that one in .xml and moved everything else to .groovy. I found that this one is the real culprit by just hit and trial. In the logs there was nothing which points me to this.
|
 |
Peter Ledbrook
author
Greenhorn
Joined: Jul 15, 2009
Posts: 25
|
|
Do you know that you can use / as a string delimiter? If you use that, you don't need to escape backslashes. For example:
Cheers,
Peter
|
 |
Paras Jain
Ranch Hand
Joined: Feb 26, 2005
Posts: 137
|
|
Thanks Peter.
I tried using / as the delimiter. But in my string I have curly braces too. These curly braces don't seem to be escaped by /
|
 |
 |
|
|
subject: Beans from resources.groovy not beging picked up by DI
|
|
|