grailsApplication not being injected in controller

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|

grailsApplication not being injected in controller

Arash Sharif
Hello!

I am in process of upgrading 1.3.7 application to 2.0.0 and am having
problems with grailsApplication not being injected in the
controller....


i'm just using the following:

def grailsApplication


but using grailsApplication.config throws a

java.lang.NullPointerException: Cannot get property 'config' on null object



if i use

grailsApplication.config

then i get:

Constructor threw exception; nested exception is
groovy.lang.MissingMethodException

Any help?

Arash

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

Arash Sharif
update...

seems like all dependency injection by convention is broken.  I have
to use @AutoWired for everything that's not in the resource.groovy....


any ideas?

On Thu, Dec 15, 2011 at 5:29 PM, Arash Sharif <[hidden email]> wrote:

> Hello!
>
> I am in process of upgrading 1.3.7 application to 2.0.0 and am having
> problems with grailsApplication not being injected in the
> controller....
>
>
> i'm just using the following:
>
> def grailsApplication
>
>
> but using grailsApplication.config throws a
>
> java.lang.NullPointerException: Cannot get property 'config' on null object
>
>
>
> if i use
>
> grailsApplication.config
>
> then i get:
>
> Constructor threw exception; nested exception is
> groovy.lang.MissingMethodException
>
> Any help?
>
> Arash

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

bobbywarner
I don't face any issues with dependency injection (custom services or grailsApplication) in controllers with 2.0 Final.  Can you please provide more details about your issue?  What does the rest of the controller look like?  What else are you trying to inject?


Thanks,
Bobby
Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

Neeraj Wasan
In reply to this post by Arash Sharif

where are you doing this grailsApplication.config ?

On Dec 16, 2011 7:00 AM, "Arash Sharif" <[hidden email]> wrote:
Hello!

I am in process of upgrading 1.3.7 application to 2.0.0 and am having
problems with grailsApplication not being injected in the
controller....


i'm just using the following:

def grailsApplication


but using grailsApplication.config throws a

java.lang.NullPointerException: Cannot get property 'config' on null object



if i use

grailsApplication.config

then i get:

Constructor threw exception; nested exception is
groovy.lang.MissingMethodException

Any help?

Arash

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

Arash Sharif

In a service

On Dec 21, 2011 6:57 AM, "Neeraj Wasan" <[hidden email]> wrote:

where are you doing this grailsApplication.config ?

On Dec 16, 2011 7:00 AM, "Arash Sharif" <[hidden email]> wrote:
Hello!

I am in process of upgrading 1.3.7 application to 2.0.0 and am having
problems with grailsApplication not being injected in the
controller....


i'm just using the following:

def grailsApplication


but using grailsApplication.config throws a

java.lang.NullPointerException: Cannot get property 'config' on null object



if i use

grailsApplication.config

then i get:

Constructor threw exception; nested exception is
groovy.lang.MissingMethodException

Any help?

Arash

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

Neeraj Wasan

if you are writing it outside of the methods then it will not work. Write it inside your service methods.

On Dec 21, 2011 9:29 PM, "Arash Sharif" <[hidden email]> wrote:

In a service

On Dec 21, 2011 6:57 AM, "Neeraj Wasan" <[hidden email]> wrote:

where are you doing this grailsApplication.config ?

On Dec 16, 2011 7:00 AM, "Arash Sharif" <[hidden email]> wrote:
Hello!

I am in process of upgrading 1.3.7 application to 2.0.0 and am having
problems with grailsApplication not being injected in the
controller....


i'm just using the following:

def grailsApplication


but using grailsApplication.config throws a

java.lang.NullPointerException: Cannot get property 'config' on null object



if i use

grailsApplication.config

then i get:

Constructor threw exception; nested exception is
groovy.lang.MissingMethodException

Any help?

Arash

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

Arash Sharif

So it doesn't get injected anymore?   Like I mentioned def grailsApplocation as a class variable does not get injected.  Using @autowired works.

On Dec 21, 2011 8:04 AM, "Neeraj Wasan" <[hidden email]> wrote:

if you are writing it outside of the methods then it will not work. Write it inside your service methods.

On Dec 21, 2011 9:29 PM, "Arash Sharif" <[hidden email]> wrote:

In a service

On Dec 21, 2011 6:57 AM, "Neeraj Wasan" <[hidden email]> wrote:

where are you doing this grailsApplication.config ?

On Dec 16, 2011 7:00 AM, "Arash Sharif" <[hidden email]> wrote:
Hello!

I am in process of upgrading 1.3.7 application to 2.0.0 and am having
problems with grailsApplication not being injected in the
controller....


i'm just using the following:

def grailsApplication


but using grailsApplication.config throws a

java.lang.NullPointerException: Cannot get property 'config' on null object



if i use

grailsApplication.config

then i get:

Constructor threw exception; nested exception is
groovy.lang.MissingMethodException

Any help?

Arash

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

Jeff Scott Brown
On Wed, Dec 21, 2011 at 10:30 AM, Arash Sharif <[hidden email]> wrote:

> So it doesn't get injected anymore?   Like I mentioned def grailsApplocation
> as a class variable does not get injected.  Using @autowired works.
>
> On Dec 21, 2011 8:04 AM, "Neeraj Wasan" <[hidden email]> wrote:
>>
>> if you are writing it outside of the methods then it will not work. Write
>> it inside your service methods.
>>
>> On Dec 21, 2011 9:29 PM, "Arash Sharif" <[hidden email]> wrote:
>>>
>>> In a service
>>>
>>> On Dec 21, 2011 6:57 AM, "Neeraj Wasan" <[hidden email]> wrote:
>>>>
>>>> where are you doing this grailsApplication.config ?
>>>>
>>>> On Dec 16, 2011 7:00 AM, "Arash Sharif" <[hidden email]> wrote:
>>>>>
>>>>> Hello!
>>>>>
>>>>> I am in process of upgrading 1.3.7 application to 2.0.0 and am having
>>>>> problems with grailsApplication not being injected in the
>>>>> controller....
>>>>>
>>>>>
>>>>> i'm just using the following:
>>>>>
>>>>> def grailsApplication
>>>>>
>>>>>
>>>>> but using grailsApplication.config throws a
>>>>>
>>>>> java.lang.NullPointerException: Cannot get property 'config' on null
>>>>> object
>>>>>
>>>>>
>>>>>
>>>>> if i use
>>>>>
>>>>> grailsApplication.config
>>>>>
>>>>> then i get:
>>>>>
>>>>> Constructor threw exception; nested exception is
>>>>> groovy.lang.MissingMethodException
>>>>>
>>>>> Any help?
>>>>>
>>>>> Arash
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe from this list, please visit:
>>>>>
>>>>>    http://xircles.codehaus.org/manage_email
>>>>>
>>>>>
>


The grailsApplication bean is auto wired into services.  There must be
some other factor here that isn't clear in the thread so far.  Can you
show the service class that is causing the problem?




jb
--
Jeff Brown
SpringSource
http://www.springsource.com/

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

wpfeiffe
I'm running into the same issue on the Spring Security UI plugin abstract AbstractS2UiControllerPlugin class.  I also upgraded my app from 1.3.7 to 2.0.0 Final and was running through some testing when I encountered the GrailsApplication not being injected into that class.  After reading this thread, I modified the AbstractS2UiControllerPlugin code to use the @autowired annotation and it worked, meaning the GrailsApplication object was properly injected.  

This thread looks dead and I can repost this but these issues seem strangely similar.
Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

asandoval95
wpfeiffe wrote
I'm running into the same issue on the Spring Security UI plugin abstract AbstractS2UiControllerPlugin class.  I also upgraded my app from 1.3.7 to 2.0.0 Final and was running through some testing when I encountered the GrailsApplication not being injected into that class.  After reading this thread, I modified the AbstractS2UiControllerPlugin code to use the @autowired annotation and it worked, meaning the GrailsApplication object was properly injected.  

This thread looks dead and I can repost this but these issues seem strangely similar.
The same with me, I upgrade to grails 2.0, I am using spring Security UI plugin and it crashes because  GrailsApplication is not being injected into AbstractS2UiControllerPlugin :S
Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

Arash Sharif

Sorry I haven't respnded.  Ill post entire service but I've got it to work via plain ol java autowired anotation in the service.   Anyone else tried that?

On Jan 5, 2012 11:31 AM, "asandoval95" <[hidden email]> wrote:

wpfeiffe wrote
>
> I'm running into the same issue on the Spring Security UI plugin abstract
> AbstractS2UiControllerPlugin class.  I also upgraded my app from 1.3.7 to
> 2.0.0 Final and was running through some testing when I encountered the
> GrailsApplication not being injected into that class.  After reading this
> thread, I modified the AbstractS2UiControllerPlugin code to use the
> @autowired annotation and it worked, meaning the GrailsApplication object
> was properly injected.
>
> This thread looks dead and I can repost this but these issues seem
> strangely similar.
>

The same with me, I upgrade to grails 2.0, I am using spring Security UI
plugin and it crashes because  GrailsApplication is not being injected into
AbstractS2UiControllerPlugin :S

--
View this message in context: http://grails.1312388.n4.nabble.com/grailsApplication-not-being-injected-in-controller-tp4202876p4266709.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


pgf
Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

pgf
In reply to this post by Jeff Scott Brown
I am having the same problem after upgrading to 2.0. Here is my service:

package com.ibm.gnm

//import org.codehaus.groovy.grails.commons.ConfigurationHolder
import org.codehaus.groovy.grails.commons.GrailsApplication
import javax.xml.bind.ValidationException

/**
 * Verifies, stores and provides access to custom configuration properties.
 *
 * @throws ValidationException on missing required properties
 * 
 * @author Peter Farr, LPI Solutions
 */
class ConfigService {

	private String dbDriver
	private String dbUrl
	private String dbUser
	private String dbPasswd

	ConfigService() {
		
		def grailsApplication

		dbDriver = grailsApplication.config.gnm.alarmpoint.dbDriver
		if ( dbDriver == null ){
			throw new ValidationException("dbDriver not specified in config file")
		}
		
		dbUrl = grailsApplication.config.gnm.alarmpoint.dbUrl
		if ( dbUrl == null ){
			throw new ValidationException("dbUrl not specified in config file")
		}
		
		dbUser = grailsApplication.config.gnm.alarmpoint.dbUser
		if ( dbUser == null ){
			throw new ValidationException("dbUser not specified in config file")
		}
		
		dbPasswd = grailsApplication.config.gnm.alarmpoint.dbPasswd
		if ( dbPasswd == null ){
			throw new ValidationException("dbPasswd not specified in config file")
		}

	}

}

I tried a suggestion from a previous poster and moved the "def grailsApplication" from the class to the method - no difference. I also found JIRA 7824 (http://jira.grails.org/browse/GRAILS-7824) so I tried "GrailsApplication grailsApplication", also with no effect. Null pointer exceptions each time. If I can't get this resolved soon I'll have to go back to the depreciated CongigurationHolder.

Regards,

Peter Farr
Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

basejump (Josh)
its probably being injected but you can't use it in your constructor as its not injected until after you have a constructed instance (its not a static def)
you rarely will want to use the constructor for much of anything in the spring/grails world
use the @PostConstruct annotation on an init method and do it there or implement spring InitializingBean and set your properties in afterPropertiesSet or  

On Jan 11, 2012, at 9:50 AM, pgf wrote:

> I am having the same problem after upgrading to 2.0. Here is my service:
>
>
>
> I tried a suggestion from a previous poster and moved the "def
> grailsApplication" from the class to the method - no difference. I also
> found JIRA 7824 (http://jira.grails.org/browse/GRAILS-7824) so I tried
> "GrailsApplication grailsApplication", also with no effect. Null pointer
> exceptions each time. If I can't get this resolved soon I'll have to go back
> to the depreciated CongigurationHolder.
>
> -----
>
> Regards,
>
> Peter Farr
> --
> View this message in context: http://grails.1312388.n4.nabble.com/grailsApplication-not-being-injected-in-controller-tp4202876p4285848.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


pgf
Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

pgf
Sounds reasonable, but no go. I changed the constructor method name to configServiceInit()  then called configServiceInit() from a getter:

    def getDbUser() {
		configServiceInit()
		dbUser
    }

Bu this point I would hope the GrailsApplication object would be initialized. Still get a null pointer exception on property "config" when I call getDbUser(). Something seems badly broken.

Regards,

Peter Farr
Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

sfines
I've run into the same problem- I cannot get grailsApplication to inject with any of the previously suggested methods. I wound up implementing ApplicationContextAware and fetching the grailsApplication bean. This worked for me but I really don't like it.
Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

basejump (Josh)
In reply to this post by pgf
best bet is to create a dirt simple sandbox application that reproduces the issue. if you can reproduce it then you can create a jira with your test app attached and it will get fixed quickly.
When I do this, 75% of the time I find its not a bug but something I am doing/configuring wrong or weird, some plugin is the culprit, or at I find a simple acceptable work around that accomplished what I want.

 grailsAplplication is injected into both services and controllers fine in all of our plugins and apps for 2.0 so you must have either found a bug or your accessing/injecting it the wrong way


On Jan 11, 2012, at 12:02 PM, pgf wrote:

> Sounds reasonable, but no go. I changed the constructor method name to
> configServiceInit()  then called configServiceInit() from a getter:
>
>
>
> Bu this point I would hope the GrailsApplication object would be
> initialized. Still get a null pointer exception on property "config" when I
> call getDbUser(). Something seems badly broken.
>
> -----
>
> Regards,
>
> Peter Farr
> --
> View this message in context: http://grails.1312388.n4.nabble.com/grailsApplication-not-being-injected-in-controller-tp4202876p4286298.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

Jeff Scott Brown
On Wed, Jan 11, 2012 at 2:41 PM, Josh (basejump) <[hidden email]> wrote:
> best bet is to create a dirt simple sandbox application that reproduces the issue. if you can reproduce it then you can create a jira with your test app attached and it will get fixed quickly.
> When I do this, 75% of the time I find its not a bug but something I am doing/configuring wrong or weird, some plugin is the culprit, or at I find a simple acceptable work around that accomplished what I want.
>
>  grailsAplplication is injected into both services and controllers fine in all of our plugins and apps for 2.0 so you must have either found a bug or your accessing/injecting it the wrong way
>
>

What Josh said.  ;)

A simple application which clearly demonstrates the problem is often a
really big help for us when trying to troubleshoot a potential problem
with the framework.

Thanks for the help.



jb
--
Jeff Brown
SpringSource
http://www.springsource.com/

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


pgf
Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

pgf
In reply to this post by basejump (Josh)
Okay, I've recreated it in a simple, newly created Grails project. Just to be sure I am not doing something completely wrong before opening a JIRA, here is what I did:

1. Create an new Grails 2.0 project in STS
2. Create a domain called User
3. Created the controller and views for User (i.e. UserController)
4. Created a service with one method called readFoo() as below
5. Added a line to Config.groovy to be read.
6. Injected my service into UserController and added a call to readFoo() in the list() method

When I hit http://localhost:8080/Simple/user/list I get a null pointer exception "Cannot get property 'config' on null object". Here is my service class:
package simple

class TestService {

	def readFoo() {
		def grailsApplication
		
		def paramter = grailsApplication.config.simple.parameter
		return parameter
	}
}

I believe this should have worked.

Regards,

Peter Farr
Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

basejump (Josh)
spring will only inject at the class level. move the def grailsApplication, clean and try again

class TestService {
        def grailsApplication

        def readFoo() {
                assert grailsApplication.config
                def paramter = grailsApplication.config.simple.parameter
                return parameter
        }
}


On Jan 11, 2012, at 8:06 PM, pgf wrote:

> Okay, I've recreated it in a simple, newly created Grails project. Just to be
> sure I am not doing something completely wrong before opening a JIRA, here
> is what I did:
>
> 1. Create an new Grails 2.0 project in STS
> 2. Create a domain called User
> 3. Created the controller and views for User (i.e. UserController)
> 4. Created a service with one method called readFoo() as below
> 5. Added a line to Config.groovy to be read.
> 6. Injected my service into UserController and added a call to readFoo() in
> the list() method
>
> When I hit http://localhost:8080/Simple/user/list I get a null pointer
> exception "Cannot get property 'config' on null object". Here is my service
> class:
>
>
> I believe this should have worked.
>
> -----
>
> Regards,
>
> Peter Farr
> --
> View this message in context: http://grails.1312388.n4.nabble.com/grailsApplication-not-being-injected-in-controller-tp4202876p4287600.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: grailsApplication not being injected in controller

arbeitinlaufen
In reply to this post by wpfeiffe
Could you please post your changes to AbstractS2UiController, I'm running into the same problem.
12