Grails Application context?

Typically, you wouldn’t need to change application context on each user login. Spring Context contains objects that typically live as long as the application and are generally not user-dependent. Maybe you wish to expand your question and explain your scenario since based on what you said so far it doesn’t seem that you are on the right track.

Up vote 0 down vote favorite 1 share g+ share fb share tw.

I have a grails / groovy application running under tomcat. For some reason I have to be able to change the application context dynamically. That is, I want to be able (at login time) to set this context.

I know that this is doable via the Config. Groovy but this is static. At login time I am getting a parameter which is the context for the application.

How can I set this context? Thanks in advance. Luis grails groovy link|improve this question edited Nov 30 '10 at 21:02skaffman114k8136227 asked Oct 23 '09 at 15:47Luixv2,2611437 82% accept rate.

Typically, you wouldn’t need to change application context on each user login. Spring Context contains objects that typically live as long as the application and are generally not user-dependent. Maybe you wish to expand your question and explain your scenario since based on what you said so far it doesn’t seem that you are on the right track.

In one application, we had a different data source depending on the enterprise that user belonged. Even than, context was not affected, only the user session and a bit of meddling with OpenSessionInView filter. If, for whatever reason, you need to intervene the Spring ApplicationContext programmatically, you can do it by getting hold of Context by the means of ApplicationContextAware interface.

Then you can manipulate the context, for example add new bean definitions, chain contexts (see setParent) etc. You can use BeanDefinitionBuilder to construct your bean and then call the registerBean method on GenericApplicationContext. You can get a hold of ApplicationContext by making your service for example ApplicationContextAware. Then you can invoke registerBean method from your controller.

Take a look at this code: import org.springframework.context. ApplicationContext import org.springframework.context. ApplicationContextAware import org.springframework.beans.factory.config.

ConfigurableListableBeanFactory import org.springframework.beans.factory.support. BeanDefinitionBuilder class MyRedefiningService implements ApplicationContextAware { def context void setApplicationContext(ApplicationContext context) { this. Context = context } void registerBean(){ BeanDefinitionBuilder builderA = BeanDefinitionBuilder .

RootBeanDefinition(DummyService. Class) context. RegisterBeanDefinition("bean-a", builderA.

GetBeanDefinition()); println context. GetBean("bean-a"); } } //controller class class SomeController { def myRedefining def index = { myRedefining.registerBean() } }.

I really do not understand exactly how to use your hint. I really would appreciate if you can specify a little bit more how to use your approach. Thanks a lot.

Luis – Luixv Oct 25 '09 at 11:30 I expanded my answer. If it is still not clear, maybe it is best if you describe the problem you are facing in more detail. – Dan Oct 26 '09 at 13:51.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions