簡體   English   中英

關於在以下應用程序中添加spring jmx功能

[英]Regarding adding spring jmx functionality in the below application

我是JMX世界的新手,到目前為止我已經探索過它主要用於監視和管理應用程序,因為我對spring JMX非常感興趣,我已經開發了這個接口和類, 你能告訴我如何特別是對於JMX特別適用於彈簧,需要在spring xml中進行哪些設置 ...

package dustin.jmx.modelmbeans;

/**
 * Interface to expose Model MBean via Spring.
 */
public interface SimpleCalculatorIf
{
   public int add(final int augend, final int addend);

   public int subtract(final int minuend, final int subtrahend);

   public int multiply(final int factor1, final int factor2);

   public double divide(final int dividend, final int divisor);
} 

以下是班級..

package dustin.jmx.modelmbeans;


public class SimpleCalculator implements SimpleCalculatorIf
{
   /**
    * Calculate the sum of the augend and the addend.
    *
    * @param augend First integer to be added.
    * @param addend Second integer to be added.
    * @return Sum of augend and addend.
    */
   public int add(final int augend, final int addend)
   {
      return augend + addend;
   }

   /**
    * Calculate the difference between the minuend and subtrahend.
    * 
    * @param minuend Minuend in subtraction operation.
    * @param subtrahend Subtrahend in subtraction operation.
    * @return Difference of minuend and subtrahend.
    */
   public int subtract(final int minuend, final int subtrahend)
   {
      return minuend - subtrahend;
   }

   /**
    * Calculate the product of the two provided factors.
    *
    * @param factor1 First integer factor.
    * @param factor2 Second integer factor.
    * @return Product of provided factors.
    */
   public int multiply(final int factor1, final int factor2)
   {
      return factor1 * factor2;
   }

   /**
    * Calculate the quotient of the dividend divided by the divisor.
    *
    * @param dividend Integer dividend.
    * @param divisor Integer divisor.
    * @return Quotient of dividend divided by divisor.
    */
   public double divide(final int dividend, final int divisor)
   {
      return dividend / divisor;
   }
}

1)將SimpleCalculatorIf重命名為SimpleCalculatorMBean。 然后,context.xml中的這兩行就足以讓Spring檢測並將你的SimpleCalculator注冊為MBean http://docs.oracle.com/javase/tutorial/jmx/mbeans/standard.html

<context:mbean-export/>
<bean class="dustin.jmx.modelmbeans.SimpleCalculator"/>

2)但最有效的方法是使用Spring注釋,然后你甚至不需要一個接口

@ManagedResource(objectName="bean:name=SimpleCalculator", description="My Managed Calculator", log=true,
logFile="jmx.log", currencyTimeLimit=15, persistPolicy="OnUpdate", persistPeriod=200,
persistLocation="foo", persistName="bar")
public class SimpleCalculator implements SimpleCalculatorIf
{
   @ManagedOperation
   public int add(final int augend, final int addend)
   {
      return augend + addend;
   }
   ...

實際默認@ManagedResource沒有param也可以工作,我只是想顯示你有多少注釋選項。 閱讀Spring文檔中的更多內容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM