views:

229

answers:

1

I want to deploy the same .war file to two different virtual hosts on the same Tomcat 6 instance. However, I am running into a problem with the Spring framework and registering a bean. Here is the error I am seeing...

org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [com.dti.servlets.Configuration@3a1834] with key 'EAM:name=webConfig'; nested exception is javax.management.InstanceAlreadyExistsException: EAM:name=webConfig

I am pretty sure that I need to define my contexts for each virtual host but I am not having any luck. The only fix I have found that works is to change the name of the bean key. Any other suggestions would be great.

+1  A: 

The problem is that the name of the bean must be unique per JVM. Since you're deploying the same war twice, you have two solutions:

  1. change the registration behaviour of the Spring JMX exporter (see the documentation)
  2. define your own ObjectNamingStrategy to dynamically change the name of the beans at startup (you would end up with names like app1.mybean and app2.mybean)
Vladimir
I suggested that already, and got yelled at for my troubles :)
skaffman
I wouldn't go with the (1) but IMO the (2) is completely justifiable: you use JMX annotations and include the same class in two of your wars (is not quite surprising). I only found (2) to solve that problem but if someone has another solution, I'm all ear :-)
Vladimir
Thanks Vladimir, this is the kind of info I was hoping for. Skaffman, I don't know what your are talking about but you didn't provide any of this information. We could compare the your answer to this one but somehow it has mysteriously been removed. Also, how do you get "yelled" at in a forum? All I said was that you basically restated my question without providing any new information. Didn't mean to offend, sorry.Thanks again, Vladimir.
R.P.