Grails message.properties changes not taking effec

2019-05-27 09:49发布

I have a really annoying problem with a deployed Grails application on tomcat 7

I created a tool in my website that basically allows the site admin to edit message.properties files so that he can change the messages for a certain language as he desire.

All the changes are saved successfully to the file he edited.

In development, while running the website from STS (Soring Source Tools Suite; somethng like eclips) I just refresh the website in the browser and I see the changes instantly, all the changes that made to the message.properties file for the selected language is taking effect correctly.

But in the deployed application (same code same config no errors) the admin do the same thing, edit the resources in the same way as before, the message.properties file is saved with the new values correctly, but, I dont see the changes in the browser, unless I restarted tomcat, or after number of hours!

I've disabled the tomcat 7 caching, and I still face the same problem. I've spent more than 4 days googling, but all the results are not related to my problem, and most of them are related to hibernate caching.

So, my question simply is as follows:

I want to go to a message.properties file in my deployed grails application, lets say message_en.properties, change lets say default.welcome.message=Welcome to default.welcome.message=Hello, World! And then open any browser, and see Hello, World! instead of Welcome

Thanks in advance for any help =')

2条回答
看我几分像从前
2楼-- · 2019-05-27 10:30

Deployed application will not pick up changes until you restart it. Changes are reloaded on-thy-fly only in development mode for your convenience. It is called "hot-deployment" because only parts that are changed (messages.properties in your case) are applied.

If you want to edit messages in deployed application you can apply alternative solution - localisation plugin that keeps your messages in database.

查看更多
甜甜的少女心
3楼-- · 2019-05-27 10:36

As they say, some big questions have a very simple answer! Depending on a post I found, in my resources editor tool, I added this code in my action with other few changes in the bootstarp (see link at the end of the answer):

def messageSource
def saveMessageResources={
    .
    .
    .
    //my action logic
    .
    .
    .    
    messageSource.clearCache()
}

and it worked :)

References: http://jira.grails.org/browse/GPAPPENGINE-44

查看更多
登录 后发表回答