Results 1 to 10 of 10

Thread: Spring / Grails integration

Hybrid View

  1. #1
    Join Date
    Apr 2012
    Posts
    9

    Question Spring / Grails integration

    Hello all,

    I need to create a Spring MVC Webapplication but I would like to use Grails for front end.

    What is the best way?
    How do I integrate Spring with Grails?
    Shall I use the Grails Controllers or the Spring Controllers ?
    What do I need to do ?

    All sugestions are welcomed

    Thanks a lot for your cooperation

    Kind regards
    Luis Silva

  2. #2
    Join Date
    Apr 2012
    Posts
    4

    Default

    Quote Originally Posted by luisfrps View Post
    Hello all,

    I need to create a Spring MVC Webapplication but I would like to use Grails for front end.

    What is the best way?
    How do I integrate Spring with Grails?
    Shall I use the Grails Controllers or the Spring Controllers ?
    What do I need to do ?

    All sugestions are welcomed

    Thanks a lot for your cooperation

    Kind regards
    Luis Silva
    I am not sure what you are getting at with "How do I integrate Spring with Grails?". In Grails we use Spring for a lot of things like dependency injection, data binding, transaction management, etc. Can you clarify what you mean with the question?

  3. #3
    Join Date
    Apr 2012
    Posts
    9

    Question Groovy issue

    Hello,

    The thing is:

    I decided to create a separate project with Spring and Hibernate just to retrieve information from the DB using Hibernate (instead of letting Grails do it for me under the covers..) but I still want the Grails for the Controller and UI *.gsp.
    *
    In the Grails project I clicked on Properties/Project references/ and selected my "Spring and Hibernate" project so that*my "Grails" project and my "Spring and Hibernate " projects are now connected.
    *
    Inside it compiles with no errors, I can indeed access the java class I defined in my "Spring and Hibernate" project inside a java class of my "Grails" project. If I run the Grails application as a Java application I can acess the java class I defined in my "Spring and Hibernate" with no problem at all. The problem is when I try to run the Grails application.
    Grails console shows an error saying that the java class I defined in the "Spring and Hibermate" project does not exist!
    *
    Do you know what to do in order to solve this dependency?
    *
    Thanks a lot for your cooperation!
    *
    Best regards
    Luis

  4. #4
    Join Date
    Apr 2012
    Posts
    4

    Default

    Quote Originally Posted by luisfrps View Post
    Hello,

    The thing is:

    I decided to create a separate project with Spring and Hibernate just to retrieve information from the DB using Hibernate (instead of letting Grails do it for me under the covers..) but I still want the Grails for the Controller and UI *.gsp.
    *
    In the Grails project I clicked on Properties/Project references/ and selected my "Spring and Hibernate" project so that*my "Grails" project and my "Spring and Hibernate " projects are now connected.
    *
    Inside it compiles with no errors, I can indeed access the java class I defined in my "Spring and Hibernate" project inside a java class of my "Grails" project. If I run the Grails application as a Java application I can acess the java class I defined in my "Spring and Hibernate" with no problem at all. The problem is when I try to run the Grails application.
    Grails console shows an error saying that the java class I defined in the "Spring and Hibermate" project does not exist!
    *
    Do you know what to do in order to solve this dependency?
    *
    Thanks a lot for your cooperation!
    *
    Best regards
    Luis

    It sounds to me like at least part of your struggle has to do with getting your projects configured in the IDE. I am not sure why you want 2 projects. If you have a bunch of Java or Groovy code that talks to the database (or does just about anything else for that matter) you can put that code in the Grails application under src/groovy or src/java and all of that code is now part of the Grails project.

    It is hard to say without knowing more details about your code but you are probably going to want Grails to help you do things like inject instances of those classes into Grails services and/or controllers by registering corresponding beans in the spring application context, which is very simple to do.

    If you leave this as 2 separate projects then you have to figure out what that means at deployment time. From what you said above, I don't know why you might want 2 separate projects. If for whatever reason you really do need 2 separate projects, you could bundle the non-Grails code up as a library and use that library in the Grails application just like you would use any other library.

    The simplest thing is to just put the code in the Grails application and be done with it. There may be good reasons not to go that route, but they aren't described in this thread so far so I would work with the idea that this is the route to go.

    Is this helping?



    jb

  5. #5
    Join Date
    Apr 2012
    Posts
    9

    Question Grails controller with Java class

    Hello all,

    Does anyone know the sintaxe for accessing a java class inside a controller in Grails

    I needed to pass the information I have of an object defined in a java package of a Grails project for the controller and vice versa

    Many thanks for you support

    Regards
    Luis Silva

  6. #6
    Join Date
    Apr 2012
    Posts
    4

    Default

    Quote Originally Posted by luisfrps View Post
    Hello all,

    Does anyone know the sintaxe for accessing a java class inside a controller in Grails

    I needed to pass the information I have of an object defined in a java package of a Grails project for the controller and vice versa

    Many thanks for you support

    Regards
    Luis Silva
    The syntax for accessing a Java class from a Grails controller is the exact same as the syntax for accessing a Groovy class from a Grails controller. There is no difference.

    Code:
    class MyController {
        def someControllerAction() {
    
            // the Widget class referenced here could be written in Java, 
            // Groovy, Scala or just about any other JVM language
            def widget = new com.myapp.Widget()
            widget.doSomethingUseful()
    
            // ...
        }
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •