What is the best way to modify a project configuration from within a plugin?

前端 未结 3 591
忘了有多久
忘了有多久 2020-12-15 14:16

As I am trying to write a Grails Plugin, I stumbled upon two problems:

  • how do I modify one of the configuration files like Config.groovy or
3条回答
  •  一向
    一向 (楼主)
    2020-12-15 15:02

    You might try changing the configuration within the MyNiftyPlugin.groovy file (assuming that your plugin is named my-nifty). I've found that I can change the configuration values within the doWithApplicationContext closure. Here's an example.

    def doWithApplicationContext = { applicationContext ->  
      def config = application.config;
      config.edu.mycollege.server.name = 'http://localhost:8080'
      config.edu.mycollege.server.instance = 'pprd'
    }
    

    The values you enter here do show up in the grailsApplication.config variable at run time. If it works for you, it will be a neater solution, because it doesn't require changes to the client project.

    I must qualify that with the fact that I wasn't able to get Spring Security to work by this technique. I believe that my plugin (which depends on Spring Security) was loaded after the security was initialized. I decided to add an extra file to the grails-app/conf directory.

    HTH.

提交回复
热议问题