日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > javascript >内容正文

javascript

JMX和Spring –第1部分

發(fā)布時(shí)間:2023/12/3 javascript 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JMX和Spring –第1部分 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
這是三篇文章的第一篇,這三篇文章將展示如何通過(guò)JMX支持為Spring應(yīng)用程序賦能。

Maven配置

這是用于設(shè)置此示例代碼的Maven pom.xml:



<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>uk.co.jemos.experiments.jmx</groupId><artifactId>jemos-jmx-experiments</artifactId><version>0.0.1-SNAPSHOT</version><name>jemos-jmx-experiments</name><description>Jemos JMX Experiments</description><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>2.3.2</version><configuration><source>1.6</source><target>1.6</target></configuration></plugin></plugins></build><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.8.2</version><scope>test</scope></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.16</version><scope>compile</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>3.0.5.RELEASE</version><scope>compile</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>3.0.5.RELEASE</version><scope>compile</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jmx</artifactId><version>2.0.8</version><scope>compile</scope></dependency> <dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>3.0.5.RELEASE</version><type>jar</type><scope>test</scope></dependency></dependencies> </project>

彈簧配置

Spring配置非常簡(jiǎn)單:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xmlns:util="http://www.springframework.org/schema/util"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"><context:property-placeholder location="classpath:jemos-jmx.properties" /><bean id="rmiRegistry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean"><property name="port" value="${jemos.jmx.rmi.port}" /></bean><bean id="jemosJmxServer" class="org.springframework.jmx.support.ConnectorServerFactoryBean"depends-on="rmiRegistry" ><property name="objectName" value="connector:name=rmi" /><property name="serviceUrl"value="service:jmx:rmi://localhost/jndi/rmi://localhost:${jemos.jmx.rmi.port}/jemosJmxConnector" /><property name="environment"><!-- the following is only valid when the sun jmx implementation is used --><map><entry key="jmx.remote.x.password.file" value="${user.home}/.secure/jmxremote.password" /><entry key="jmx.remote.x.access.file" value="${user.home}/.secure/jmxremote.access" /></map></property></bean></beans>

此配置雖然很簡(jiǎn)單,但可以滿足以下所有要求:

  • 從您的Spring應(yīng)用程序上下文中啟動(dòng)JMX服務(wù)器
  • 通過(guò)遠(yuǎn)程RMI URL公開對(duì)JMX服務(wù)器的訪問(wèn)
  • 通過(guò)身份驗(yàn)證和授權(quán)保護(hù)對(duì)JMX服務(wù)器的訪問(wèn)

關(guān)于上述配置的幾點(diǎn)注意事項(xiàng):

  • 您想外部化一些配置信息,例如RMI注冊(cè)表端口和應(yīng)用程序運(yùn)行所在的主機(jī)。 盡管我將RMI注冊(cè)表端口外部化為類路徑中的屬性文件,但我將“ localhost”保留為主機(jī)名。 在實(shí)際的生產(chǎn)環(huán)境中,尤其是當(dāng)您想水平擴(kuò)展應(yīng)用程序(例如,將其部署在不同的服務(wù)器上)時(shí),遠(yuǎn)程URL的服務(wù)器部分也應(yīng)該外部化。
  • 因?yàn)槲覀円_一個(gè)遠(yuǎn)程RMI URL,所以為了將JMX服務(wù)器公開給RMI注冊(cè)表,如果尚未啟動(dòng)一個(gè)RMI注冊(cè)表,則需要啟動(dòng)它。 這是通過(guò)聲明RmiRegistryFactoryBean發(fā)生的。 啟動(dòng)注冊(cè)表的端口必須與公開的URL相同。
  • 上面的配置未啟用基于注釋的MBean支持。 這種配置將成為我下一篇文章的主題,在該文章中,我將展示如何編寫簡(jiǎn)單的MBean來(lái)更改基于Log4j的應(yīng)用程序的日志記錄級(jí)別。 通過(guò)身份驗(yàn)證和授權(quán)保護(hù)對(duì)JMX服務(wù)器的訪問(wèn)

在以上配置中,您可能已經(jīng)注意到以下部分:

<property name="environment"><!-- the following is only valid when the sun jmx implementation is used --><map><entry key="jmx.remote.x.password.file" value="${user.home}/.secure/jmxremote.password" /><entry key="jmx.remote.x.access.file" value="${user.home}/.secure/jmxremote.access" /></map></property>

上面的代碼段聲明的是兩個(gè)文件的位置,一個(gè)用于授權(quán),一個(gè)用于認(rèn)證。 我決定將此類文件放在?/ .secure下,但該位置最終取決于您。 這些文件的內(nèi)容很簡(jiǎn)單:

JMX訪問(wèn)文件

jemosAdmin讀寫

上面的文件包含一個(gè)用戶名(jemosAdmin)及其角色(readwrite)。

JMX密碼文件

在JMX密碼文件中,您聲明用戶及其密碼:

jemosAdmin安全

這些信息到位后,您可以啟動(dòng)JMX服務(wù)器,然后通過(guò)jconsole或jvisualvm(如果使用的是JDK6或更高版本)訪問(wèn)它。

身份驗(yàn)證之后,RMI連接器實(shí)際上就可以作為Bean使用,所有Oracle的本地MBean一樣。

在我的下一篇文章中,我將展示如何編寫一個(gè)簡(jiǎn)單的Logging MBean服務(wù)的代碼,該服務(wù)可在運(yùn)行時(shí)用于更改包(及其所有子包)的日志記錄級(jí)別。 這項(xiàng)服務(wù)帶來(lái)了增加正常運(yùn)行時(shí)間的優(yōu)勢(shì),并有助于對(duì)應(yīng)用程序進(jìn)行故障排除。

繼續(xù)第2部分 。

參考: JMX和Spring –我們的JCG合作伙伴 Marco Tedone的第1部分 ,位于Marco Tedone的博客博客中。


翻譯自: https://www.javacodegeeks.com/2012/07/jmx-and-spring-part-1.html

總結(jié)

以上是生活随笔為你收集整理的JMX和Spring –第1部分的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。