Results 1 to 5 of 5

Thread: Register two Beans instances via annotations

  1. #1

    Default Register two Beans instances via annotations

    Hi,
    I am using Spring3.1

    I am getting the exception InstanceAlreadyExistsException when I try to add bean to the JMX context.

    I am using annotations in order to add this bean. how could I over pass this excpetion and register both my instances to the jmx?


    my code:


    Code:
    @ManagedResource(objectName = "ba.f:name=kkk", description = "")
    public class SessionsManagerBean
    {
    ..
    }
    xml:

    jmx configuration:

    Code:
    <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean" />
    
    	<bean id="jmxAttributeSource"
    		class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" />
    
    	<!-- will create management interface using annotation metadata -->
    	<bean id="assembler"
    		class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
    		<property name="attributeSource" ref="jmxAttributeSource" />
    	</bean>
    
    	<!-- will pick up the ObjectName from the annotation -->
    	<bean id="namingStrategy"
    		class="org.springframework.jmx.export.naming.MetadataNamingStrategy">
    		<property name="attributeSource" ref="jmxAttributeSource" />
    	</bean>
    
    
    	<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter"
    		lazy-init="false">
    
    		<property name="assembler" ref="assembler" />
    		<property name="namingStrategy" ref="namingStrategy" />
    		<property name="autodetectModeName" value="AUTODETECT_ASSEMBLER" />
    		<property name="ensureUniqueRuntimeObjectNames" value="false" />
    
    		<property name="beans">
    			<map>
    				<entry key="Server:name=HttpAdaptor">
    					<bean class="mx4j.tools.adaptor.http.HttpAdaptor">
    						<property name="port" value="8000" />
    						<property name="host" value="0.0.0.0" />
    						<property name="processor">
    							<bean class="mx4j.tools.adaptor.http.XSLTProcessor" />
    						</property>
    
    					</bean>
    				</entry>
    			</map>
    		</property>
    		<property name="listeners">
    			<list>
    				<!--
    					let the HttpAdapter be started after it is registered in the
    					MBeanServer
    				-->
    				<bean class="com.fixgw.jmx.HttpAdaptorMgr">
    					<property name="mbeanServer" ref="mbeanServer" />
    				</bean>
    			</list>
    		</property>
    	</bean>

    bean instances xml configuration:

    Code:
    <bean id="SessionsManager1" class="com.fixgw.sessions.SessionsManagerBean">
    	</bean>
    
    
    	<bean id="SessionsManager2" class="com.fixgw.sessions.SessionsManagerBean">
    	</bean>
    error:

    Code:
    Caused by: javax.management.InstanceAlreadyExistsException: ba.f:name=kkk
    	at com.sun.jmx.mbeanserver.Repository.addMBean(Unknown Source)
    	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.internal_addObject(Unknown Source)
    	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(Unknown Source)
    	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(Unknown Source)
    	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(Unknown Source)
    	at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(Unknown Source)
    	at org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(MBeanRegistrationSupport.java:169)
    	at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:655)
    	at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:592)
    	... 18 more



    thanks,
    ray.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    You cannot... The name has to be unique (AFAIK) so each needs to have a different name. You could try adding them explicitly (and not by annotations).

    Also it is easier to use the spring namespace support to configure the jmx exporter etc. saves you quite some xml.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    Weird. so there isnt a way of using jmx annotations when I have more then one instance of them same bean.

    I tried to mix both configurations but it didnt work.

    thanks.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    The name has to be unique (in a database you cannot have the sime primary key for multiple records!) and if you hardcode it in the annotation that isn't the case. You could try and create your own namingconvention (forgot the interface which does the naming) but basically you cannot do that.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Feb 2013
    Posts
    3

    Default

    you would like to find out what the properties of the spring framework. Manage resource annotation do as seen in this Java Doc. you want to understand each pa ram so I can set it to the proper value. If anyone knows where to find more info, I would appreciate it.
    supported living community
    Glenvale Supported Living
    182-184 Hursley Road Toowoomba QLD 4350 Australia
    Phone : +61 1300 765 051
    http://www.glenvalesupportedliving.com.au/
    Providing community aged care supported living housing in Toowoomba, the Glenvale Villas are the perfect option for your loved ones, if they need a little extra help with daily living.
    Last edited by Konrad78; Feb 9th, 2013 at 08:08 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •