Two spring applications, both use a certain jar and application context - how do i control from which appl i get a bean from the context?

StackOverflow https://stackoverflow.com/questions/23458051

Question

I have two Spring applications, applA and applB, running in Tomcat - both use jarX.jar and applicationContext-x.xml.
So there's going to be one instance of a certain bean, defined in the above context, for each application.
I'm exposing the bean and some of its methods via JMX by using annotations. now i want to write a test client which calls method of the bean, but sometimes i want to call the methods of the bean in applA and sometimes of the bean in applB.

How do i do that?
i also have a bean called jmxServerConfiguration in each application, each using a different port though.

currently in my JMX client i'm getting the bean by using

BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(applicationContextName);
theBean = beanFactory.getBean(BEAN_NAME);

but i always get the bean of applA. how do i tell it whether i want the bean of applB or applA?

Should i perhaps, (how?), use

MBeanServerConnection connection = JmxUtils.getMBeanServerConnection(url);

and specify a different port in the url, depending on the appl from which i want to get the bean?

Was it helpful?

Solution

Set the default-domain on the MBean exporter to a different value for each application and use the appropriate ObjectName to access the bean(s) over JMX.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top