Announcement Announcement Module
Collapse
No announcement yet.
How can I export services Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I export services

    Hi,

    I have this beans.xml:

    <beans>
    <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServer FactoryBean"/>
    <bean id="exporter" class="org.springframework.jmx.export.MBeanExporte r">
    <property name="beans">
    <map>
    <entry key="bean:name=jmxBean" value-ref="jmxBean"/>
    </map>
    </property>
    <property name="server" ref="mbeanServer"/>
    </bean>
    <bean id="jmxBean" class="service.JMXBean" init-method="init"/>
    </beans>

    JMXBean.java is:

    package service;

    public class JMXBean {

    void init() {
    System.out.println("init ...");
    }

    public int getValue() {
    return 0;
    }
    }

    I run Spring with this Main.java:

    package service;

    import org.springframework.context.support.AbstractApplic ationContext;
    import org.springframework.context.support.ClassPathXmlAp plicationContext;

    public class Main {

    public static void main(String[] args) throws InterruptedException {

    final AbstractApplicationContext ctx =
    new ClassPathXmlApplicationContext(new String []{"beans.xml"});

    Runtime.getRuntime().addShutdownHook(new Thread() {
    public void run() {
    ctx.close();
    }
    });

    Thread.sleep(Long.MAX_VALUE);
    }

    }

    I do it in such way:

    $ java -Dcom.sun.management.jmxremote -cp .:../lib/commons-logging.jar:../lib/spring.jar service/Main

    05.06.2006 15:18:38 org.springframework.core.CollectionFactory <clinit>
    INFO: JDK 1.4+ collections available
    05.06.2006 15:18:38 org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [beans.xml]
    05.06.2006 15:18:39 org.springframework.context.support.AbstractRefres hableApplicationContext refreshBeanFactory
    INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlAp plicationContext;hashCode=2693887]: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [bootstrapBean,mbeanServer,exporter,jmxBean]; root of BeanFactory hierarchy
    05.06.2006 15:18:39 org.springframework.context.support.AbstractApplic ationContext refresh
    INFO: 4 beans defined in application context [org.springframework.context.support.ClassPathXmlAp plicationContext;hashCode=2693887]
    05.06.2006 15:18:39 org.springframework.context.support.AbstractApplic ationContext initMessageSource
    INFO: Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMess ageSource@166a22b]
    05.06.2006 15:18:40 org.springframework.context.support.AbstractApplic ationContext initApplicationEventMulticaster
    INFO: Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicatio nEventMulticaster@763f5d]
    05.06.2006 15:18:40 org.springframework.beans.factory.support.DefaultL istableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [bootstrapBean,mbeanServer,exporter,jmxBean]; root of BeanFactory hierarchy]
    init ...
    05.06.2006 15:18:40 org.springframework.jmx.export.MBeanExporter afterPropertiesSet
    INFO: Registering beans for JMX exposure on startup

    But I can't see any MBean in service package, I see them only in java.lang, java.util.logging and in JMImplementation.

    Why can it be? What's wrong in my code?

  • #2
    If registering the MBeanServerFactoryBean, you can set its "locateExistingServerIfPossible" to true. Otherwise, you should be able to leave the MBeanServerFactoryBean out and remove the "server" property from your exporter. In your case, the default behaviour should work.

    Comment


    • #3
      Thanks!

      Can I run JMX service without -Dcom.sun.management.jmxremote using only Spring beans.xml?

      Comment


      • #4
        I wrote:

        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

        <beans>
        <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServer FactoryBean"/>
        <bean id="exporter" class="org.springframework.jmx.export.MBeanExporte r">
        <property name="beans">
        <map>
        <entry key="bean:name=test" value-ref="jmxBean"/>
        </map>
        </property>
        <property name="server" ref="mbeanServer"/>
        </bean>
        <bean id="jmxBean" class="service.JMXBean" init-method="init"/>
        <bean id="serverConnector" class="org.springframework.jmx.support.ConnectorSe rverFactoryBean">
        <property name="objectName" value="connector:name=rmi"/>
        <property name="serviceUrl" value="service:jmx:rmi://localhost/jndi/rmi://localhost:1099/myconnector"/>
        <property name="threaded" value="true"/>
        <property name="daemon" value="true"/>
        <property name="server">
        <ref local="mbeanServer"/>
        </property>
        </bean>
        <bean id="registry" class="org.springframework.remoting.rmi.RmiRegistr yFactoryBean">
        <property name="port" value="1099"/>
        </bean>
        </beans>

        All works fine, but how can I simplify serviceUrl for clients? Why need I setup localhost twice?

        Another problem: I tried to run JMX server on host 10.0.0.1 and client (jconsole, jManage) on host 10.0.0.2. I replaced localhost with 10.0.0.1 but connection was not established. Why can it be?

        Comment

        Working...
        X