Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7804003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:46:13+00:00 2026-06-02T01:46:13+00:00

I have a Grails service that is a wrapper around a rather complicated singleton

  • 0

I have a Grails service that is a wrapper around a rather complicated singleton object. I’d like to do some initializing to populate the singleton when the service is started. It would be nice if there was some kind of init() function that would be automatically called by the service when it starts, but I have found no such thing.

Is there a clean way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:46:16+00:00Added an answer on June 2, 2026 at 1:46 am

    You can implement InitializingBean as described by @Saurabh but that fires rather early in the Grails startup process, so while it works, the are some things that won’t be available yet, for example you can’t call GORM methods in domain classes because that happens after bean initialization. If InitializingBean isn’t sufficient you can call an initialization method from BootStrap.groovy, e.g.

    class BootStrap {
    
       def myService
    
       def init = { servletContext ->
          myService.initialize()
       }
    }
    

    and you can call the method initialize or whatever you want in the service class. You can also do the initialization work directly in BootStrap if you don’t want that code in the service class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Grails and CXF, I have published a small web service that looks like
I have a Grails command object that contains an emailAddresses field, e.g. public class
I feel like I've entered the Twilight Zone. I have a Grails form that
We have an MTOM-enabled web service that is published with Grails and the Metro
I am working with grails. I have created a service that will delete the
I'm using Grails 1.3.7. I have some code that uses the built-in base64Encode function
I have a number of Grails Services that are singleton Spring beans, not prototypes.
I have a Grails app that loads its data from xml files and delivers
I have one grails application.In that I have one model class named Book. From
I have a grails site (grails 2.0 with spring security 1.2.6) login that's supposed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.