Quantcast

Is 'environment' a reserved keyword in Grails 2.x ?

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Is 'environment' a reserved keyword in Grails 2.x ?

lionkng123
This post was updated on .
I tried to upgrade an existing project from 1.3.7 to 2.0 (final) and was getting "java.lang.IllegalArgumentException".

Then to simplify, I created a sample project with 2 domain classes to identify the problem. Codes look like:-

class EnvironmentProperty {
        String name
       
        static belongsTo = [environment : Environment]
       
        static constraints = {
                name (blank: false, nullable: false)
        }
}


class Environment {
        String name
       
        static hasMany = [environmentProperties : EnvironmentProperty]

        static constraints = {
                name (blank: false, nullable: false)
        }
}

        And found that the keyword 'environment' is main source of exception. If I remove the keyword (i.e. myEnvironment) then it's working perfectly.

       Is 'environment' a protected keyword in Grails 2.x (or Spring 3.x) ? As in 1.3x version this was working fine.



Complete Stacktrace:-
           Stacktrace has been attached as separate file to make the post clean.
            Stacktrace.txt



Regards,
Subrata
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is 'environment' a reserved keyword in Grails 2.x ?

pledbrook
I've looked at the Grails code and it seems that Grails is probably trying to auto-wire the 'environment' bean, so perhaps this is new to Spring 3.1 (which added environment/profile support) or Grails 2.0. There is apparently a related JIRA issue, but I can't find it I'm afraid.

Peter
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is 'environment' a reserved keyword in Grails 2.x ?

edward.young
This may be the jira issue for which you are looking:

http://jira.grails.org/browse/GRAILS-7851

It seems there are a few of us who are experiencing the environment name collision in similar circumstances.

The name collision is probably related to the addition of
org.springframework.core.env
Interface Environment

In Spring 3.1
http://static.springsource.org/spring/docs/3.1.0.RELEASE/javadoc-api/

Currently we're faced with the (daunting) prospect of refactoring the code to Rename/Remove the Environment domain in order to upgrade our app to Grails 2.0.

I wonder if there's a better way?


On Tue, Jan 10, 2012 at 8:30 AM, pledbrook <[hidden email]> wrote:
I've looked at the Grails code and it seems that Grails is probably trying to
auto-wire the 'environment' bean, so perhaps this is new to Spring 3.1
(which added environment/profile support) or Grails 2.0. There is apparently
a related JIRA issue, but I can't find it I'm afraid.

Peter

--
View this message in context: http://grails.1312388.n4.nabble.com/Is-environment-a-reserved-keyword-in-Grails-2-x-tp4260483p4282273.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





--
- Ed
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is 'environment' a reserved keyword in Grails 2.x ?

Daniel Glauser
What kind of idiot would name a domain class "Environment?"
*facepalm*

Daniel


On Tue, Jan 10, 2012 at 9:54 AM, Ed Young <[hidden email]> wrote:
This may be the jira issue for which you are looking:

http://jira.grails.org/browse/GRAILS-7851

It seems there are a few of us who are experiencing the environment name collision in similar circumstances.

The name collision is probably related to the addition of
org.springframework.core.env
Interface Environment

In Spring 3.1
http://static.springsource.org/spring/docs/3.1.0.RELEASE/javadoc-api/

Currently we're faced with the (daunting) prospect of refactoring the code to Rename/Remove the Environment domain in order to upgrade our app to Grails 2.0.

I wonder if there's a better way?


On Tue, Jan 10, 2012 at 8:30 AM, pledbrook <[hidden email]> wrote:
I've looked at the Grails code and it seems that Grails is probably trying to
auto-wire the 'environment' bean, so perhaps this is new to Spring 3.1
(which added environment/profile support) or Grails 2.0. There is apparently
a related JIRA issue, but I can't find it I'm afraid.

Peter

--
View this message in context: http://grails.1312388.n4.nabble.com/Is-environment-a-reserved-keyword-in-Grails-2-x-tp4260483p4282273.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





--
- Ed

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is 'environment' a reserved keyword in Grails 2.x ?

mjparme
Why is someone who names a domain object Environment an idiot? There are many use cases I can think of that could need an Environment domain.

On Jan 10, 2012, at 11:10 AM, Daniel Glauser wrote:

What kind of idiot would name a domain class "Environment?"
*facepalm*

Daniel


On Tue, Jan 10, 2012 at 9:54 AM, Ed Young <[hidden email]<mailto:[hidden email]>> wrote:
This may be the jira issue for which you are looking:

http://jira.grails.org/browse/GRAILS-7851

It seems there are a few of us who are experiencing the environment name collision in similar circumstances.

The name collision is probably related to the addition of
org.springframework.core.env
Interface Environment

In Spring 3.1
http://static.springsource.org/spring/docs/3.1.0.RELEASE/javadoc-api/

Currently we're faced with the (daunting) prospect of refactoring the code to Rename/Remove the Environment domain in order to upgrade our app to Grails 2.0.

I wonder if there's a better way?


On Tue, Jan 10, 2012 at 8:30 AM, pledbrook <[hidden email]<mailto:[hidden email]>> wrote:
I've looked at the Grails code and it seems that Grails is probably trying to
auto-wire the 'environment' bean, so perhaps this is new to Spring 3.1
(which added environment/profile support) or Grails 2.0. There is apparently
a related JIRA issue, but I can't find it I'm afraid.

Peter

--
View this message in context: http://grails.1312388.n4.nabble.com/Is-environment-a-reserved-keyword-in-Grails-2-x-tp4260483p4282273.html
Sent from the Grails - user mailing list archive at Nabble.com<http://Nabble.com>.

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

   http://xircles.codehaus.org/manage_email





--
- Ed



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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is 'environment' a reserved keyword in Grails 2.x ?

edward.young
In reply to this post by Daniel Glauser
LOL!

Yes, what kind indeed. Seems like we hit the same kind of issue with the 'Property' domain back in the early days, so it's no wonder we didn't see this coming.

;)

It wouldn't be such a big deal if the app wasn't so successful! That's your fault too!

Anyway, if anyone knows of a better solution than to refactor/rename out the Environment domain let me know.


On Tue, Jan 10, 2012 at 10:10 AM, Daniel Glauser <[hidden email]> wrote:
What kind of idiot would name a domain class "Environment?"
*facepalm*

Daniel


On Tue, Jan 10, 2012 at 9:54 AM, Ed Young <[hidden email]> wrote:
This may be the jira issue for which you are looking:

http://jira.grails.org/browse/GRAILS-7851

It seems there are a few of us who are experiencing the environment name collision in similar circumstances.

The name collision is probably related to the addition of
org.springframework.core.env
Interface Environment

In Spring 3.1
http://static.springsource.org/spring/docs/3.1.0.RELEASE/javadoc-api/

Currently we're faced with the (daunting) prospect of refactoring the code to Rename/Remove the Environment domain in order to upgrade our app to Grails 2.0.

I wonder if there's a better way?


On Tue, Jan 10, 2012 at 8:30 AM, pledbrook <[hidden email]> wrote:
I've looked at the Grails code and it seems that Grails is probably trying to
auto-wire the 'environment' bean, so perhaps this is new to Spring 3.1
(which added environment/profile support) or Grails 2.0. There is apparently
a related JIRA issue, but I can't find it I'm afraid.

Peter

--
View this message in context: http://grails.1312388.n4.nabble.com/Is-environment-a-reserved-keyword-in-Grails-2-x-tp4260483p4282273.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





--
- Ed




--
- Ed
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is 'environment' a reserved keyword in Grails 2.x ?

robelsner
In reply to this post by Daniel Glauser
On Tue, Jan 10, 2012 at 10:10 AM, Daniel Glauser <[hidden email]> wrote:
> What kind of idiot would name a domain class "Environment?"
> *facepalm*
>
> Daniel

Harsh, it seems perfectly reasonable as a name.  Having restrictions
like this should be documented.

What kind of idiotic toolkit won't let you express your data in
business domain terms?  ;)

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is 'environment' a reserved keyword in Grails 2.x ?

pledbrook
In reply to this post by edward.young
> Anyway, if anyone knows of a better solution than to refactor/rename out the
> Environment domain let me know.

You could try adding the method:

    public void setEnvironment(org.springframework.core.env.Environment env) {
        // Do nothing
    }

to the domain classes that have an 'environment' property. I'm afraid
I don't know whether it will work, but worth a shot.

Peter

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is 'environment' a reserved keyword in Grails 2.x ?

Daniel Glauser
In reply to this post by edward.young
Hi Michael,

Sorry to be offensive, I was making fun of myself.  I'm the one who chose the name, "environment."  I still think the decision made a lot of sense.

Cheers,
Daniel

On Tue, Jan 10, 2012 at 10:44 AM, Ed Young <[hidden email]> wrote:
LOL!

Yes, what kind indeed. Seems like we hit the same kind of issue with the 'Property' domain back in the early days, so it's no wonder we didn't see this coming.

;)

It wouldn't be such a big deal if the app wasn't so successful! That's your fault too!

Anyway, if anyone knows of a better solution than to refactor/rename out the Environment domain let me know.


On Tue, Jan 10, 2012 at 10:10 AM, Daniel Glauser <[hidden email]> wrote:
What kind of idiot would name a domain class "Environment?"
*facepalm*

Daniel


On Tue, Jan 10, 2012 at 9:54 AM, Ed Young <[hidden email]> wrote:
This may be the jira issue for which you are looking:

http://jira.grails.org/browse/GRAILS-7851

It seems there are a few of us who are experiencing the environment name collision in similar circumstances.

The name collision is probably related to the addition of
org.springframework.core.env
Interface Environment

In Spring 3.1
http://static.springsource.org/spring/docs/3.1.0.RELEASE/javadoc-api/

Currently we're faced with the (daunting) prospect of refactoring the code to Rename/Remove the Environment domain in order to upgrade our app to Grails 2.0.

I wonder if there's a better way?


On Tue, Jan 10, 2012 at 8:30 AM, pledbrook <[hidden email]> wrote:
I've looked at the Grails code and it seems that Grails is probably trying to
auto-wire the 'environment' bean, so perhaps this is new to Spring 3.1
(which added environment/profile support) or Grails 2.0. There is apparently
a related JIRA issue, but I can't find it I'm afraid.

Peter

--
View this message in context: http://grails.1312388.n4.nabble.com/Is-environment-a-reserved-keyword-in-Grails-2-x-tp4260483p4282273.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





--
- Ed




--
- Ed

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is 'environment' a reserved keyword in Grails 2.x ?

mjparme
Ahh, didn't realize you were the OP and were just being self-deprecating.

On Jan 10, 2012, at 12:10 PM, Daniel Glauser wrote:

Hi Michael,

Sorry to be offensive, I was making fun of myself.  I'm the one who chose the name, "environment."  I still think the decision made a lot of sense.

Cheers,
Daniel

On Tue, Jan 10, 2012 at 10:44 AM, Ed Young <[hidden email]<mailto:[hidden email]>> wrote:
LOL!

Yes, what kind indeed. Seems like we hit the same kind of issue with the 'Property' domain back in the early days, so it's no wonder we didn't see this coming.

;)

It wouldn't be such a big deal if the app wasn't so successful! That's your fault too!

Anyway, if anyone knows of a better solution than to refactor/rename out the Environment domain let me know.


On Tue, Jan 10, 2012 at 10:10 AM, Daniel Glauser <[hidden email]<mailto:[hidden email]>> wrote:
What kind of idiot would name a domain class "Environment?"
*facepalm*

Daniel


On Tue, Jan 10, 2012 at 9:54 AM, Ed Young <[hidden email]<mailto:[hidden email]>> wrote:
This may be the jira issue for which you are looking:

http://jira.grails.org/browse/GRAILS-7851

It seems there are a few of us who are experiencing the environment name collision in similar circumstances.

The name collision is probably related to the addition of
org.springframework.core.env
Interface Environment

In Spring 3.1
http://static.springsource.org/spring/docs/3.1.0.RELEASE/javadoc-api/

Currently we're faced with the (daunting) prospect of refactoring the code to Rename/Remove the Environment domain in order to upgrade our app to Grails 2.0.

I wonder if there's a better way?


On Tue, Jan 10, 2012 at 8:30 AM, pledbrook <[hidden email]<mailto:[hidden email]>> wrote:
I've looked at the Grails code and it seems that Grails is probably trying to
auto-wire the 'environment' bean, so perhaps this is new to Spring 3.1
(which added environment/profile support) or Grails 2.0. There is apparently
a related JIRA issue, but I can't find it I'm afraid.

Peter

--
View this message in context: http://grails.1312388.n4.nabble.com/Is-environment-a-reserved-keyword-in-Grails-2-x-tp4260483p4282273.html
Sent from the Grails - user mailing list archive at Nabble.com<http://Nabble.com>.

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

   http://xircles.codehaus.org/manage_email





--
- Ed




--
- Ed



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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is 'environment' a reserved keyword in Grails 2.x ?

edward.young
In reply to this post by Daniel Glauser
Yes, apologies to anyone offended by the little inside joke between Daniel and myself. It makes perfect sense and I'm sure there are many others who have used similarly common class names.

Hopefully so, because it will make the odds of finding a simple solution more likely.

On Tue, Jan 10, 2012 at 11:10 AM, Daniel Glauser <[hidden email]> wrote:
Hi Michael,

Sorry to be offensive, I was making fun of myself.  I'm the one who chose the name, "environment."  I still think the decision made a lot of sense.

Cheers,
Daniel

On Tue, Jan 10, 2012 at 10:44 AM, Ed Young <[hidden email]> wrote:
LOL!

Yes, what kind indeed. Seems like we hit the same kind of issue with the 'Property' domain back in the early days, so it's no wonder we didn't see this coming.

;)

It wouldn't be such a big deal if the app wasn't so successful! That's your fault too!

Anyway, if anyone knows of a better solution than to refactor/rename out the Environment domain let me know.


On Tue, Jan 10, 2012 at 10:10 AM, Daniel Glauser <[hidden email]> wrote:
What kind of idiot would name a domain class "Environment?"
*facepalm*

Daniel


On Tue, Jan 10, 2012 at 9:54 AM, Ed Young <[hidden email]> wrote:
This may be the jira issue for which you are looking:

http://jira.grails.org/browse/GRAILS-7851

It seems there are a few of us who are experiencing the environment name collision in similar circumstances.

The name collision is probably related to the addition of
org.springframework.core.env
Interface Environment

In Spring 3.1
http://static.springsource.org/spring/docs/3.1.0.RELEASE/javadoc-api/

Currently we're faced with the (daunting) prospect of refactoring the code to Rename/Remove the Environment domain in order to upgrade our app to Grails 2.0.

I wonder if there's a better way?


On Tue, Jan 10, 2012 at 8:30 AM, pledbrook <[hidden email]> wrote:
I've looked at the Grails code and it seems that Grails is probably trying to
auto-wire the 'environment' bean, so perhaps this is new to Spring 3.1
(which added environment/profile support) or Grails 2.0. There is apparently
a related JIRA issue, but I can't find it I'm afraid.

Peter

--
View this message in context: http://grails.1312388.n4.nabble.com/Is-environment-a-reserved-keyword-in-Grails-2-x-tp4260483p4282273.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





--
- Ed




--
- Ed




--
- Ed
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is 'environment' a reserved keyword in Grails 2.x ?

Scott Davis-7
In reply to this post by Daniel Glauser
Reminds me of a sample app I wrote awhile ago:

class Student {...}
class Teacher{...}
class Class{ //D'oh! }

SQL collisions are always fun as well:

class Message{
  String to
  String from
  // Let the SQLExceptions fly!!!
  // select to, from from message where from = 'Scott';
}

-s
Scott Davis
http://thirstyhead.com

On Jan 10, 2012, at 11:10 AM, Daniel Glauser wrote:

> Hi Michael,
>
> Sorry to be offensive, I was making fun of myself.  I'm the one who chose the name, "environment."  I still think the decision made a lot of sense.
>
> Cheers,
> Daniel
>


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is 'environment' a reserved keyword in Grails 2.x ?

Daniel Glauser
Turns out I'm in Spring training right now so I asked the instructor if there was a way to tell Spring not to autowire certain properties within an application scope.  One thing to try is defining your own application-context.xml but more likely you would need to patch in to the bean lifecycle with either a BeanFactoryPostProcessor or a BeanPostProcessor.  Since a Grails app is a Spring app you can tap into these lifecycle callbacks.  You can also programmatically alter annotations.


Search for "4.6.1 Lifecycle Callbacks"

Below are some notes from the class on the Spring bean lifecycle:
Instantiate application context
Parse XML
Bean definitions loaded into ApplicationContext
BeanFactoryPostProcessor invoked
Instantiate bean X
Dependency injection wires bean dependencies
BeanPostProcessor initializes bean
BeanPostProcessor injects proxies
Get bean
Invoke business method on bean
Close application context

This may not work but could be worth some experimentation.  What I think you need to do is tell Spring, "Please autowire environment at a domain class and the not the new environment thingy for my domain classes."  Perhaps match a group of classes within a package (so you don't shoot yourself in the foot after you add new classes).

Good luck,
Daniel


On Tue, Jan 10, 2012 at 1:11 PM, Scott Davis <[hidden email]> wrote:
Reminds me of a sample app I wrote awhile ago:

class Student {...}
class Teacher{...}
class Class{ //D'oh! }

SQL collisions are always fun as well:

class Message{
 String to
 String from
 // Let the SQLExceptions fly!!!
 // select to, from from message where from = 'Scott';
}

-s
Scott Davis
http://thirstyhead.com

On Jan 10, 2012, at 11:10 AM, Daniel Glauser wrote:

> Hi Michael,
>
> Sorry to be offensive, I was making fun of myself.  I'm the one who chose the name, "environment."  I still think the decision made a lot of sense.
>
> Cheers,
> Daniel
>


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

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is 'environment' a reserved keyword in Grails 2.x ?

pledbrook
> This may not work but could be worth some experimentation.  What I think you
> need to do is tell Spring, "Please autowire environment at a domain class
> and the not the new environment thingy for my domain classes."  Perhaps
> match a group of classes within a package (so you don't shoot yourself in
> the foot after you add new classes).

I tested my 'solution' with a very simple project and it does away
with the error. It would be great if you guys could try it out to see
whether there are any unintended side-effects.

So, to repeat, in the class that has an 'environment' property, add the line:

    void setEnvironment(org.springframework.core.env.Environment env) {}

Regards,

Peter

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is 'environment' a reserved keyword in Grails 2.x ?

lionkng123
Hi Peter,

            Your solution is working properly.

            I have tested that on the example which I have mentioned earlier.

            However, at the time of incorporating this into original workspace, I am encountering BeanCreationException. Still in search of the root cause.

            Stacktrace is being attached.
                   Stacktrace.txt

Regards,
Subrata
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is 'environment' a reserved keyword in Grails 2.x ?

lionkng123
In reply to this post by Daniel Glauser
Hello Deniel,

                Autowiring 'environment' with Domain instance might have side effects as "environment" (default bean of org.springframework.core.env.Environment) bean deals with default "servletContext" and "servletConfig", "portletContext" and "portletConfig". I am not sure about how Grails is creating an abstraction over it.

       
By the way, I am curious enough to know when "Daniel In Action - 2" released?  ;-)


Regards,
Subrata

Loading...