Loading...
Spring Framework Reference Documentation 7.0.2의 Controlling ObjectName Instances for Your Beans의 한국어 번역본입니다.
아래의 경우에 피드백에서 신고해주신다면 반영하겠습니다.
감사합니다 :)
ObjectName Instances for Your Beans내부적으로, MBeanExporter는 등록하는 각 bean에 대한 ObjectName 인스턴스를 얻기 위해
ObjectNamingStrategy의 구현체에 처리를 위임합니다. 기본적으로, 기본 구현체인
KeyNamingStrategy는 beans Map의 key를 ObjectName으로 사용합니다.
추가로, KeyNamingStrategy는 beans Map의 key를 ObjectName을 resolve하기 위해
Properties file(또는 files)의 entry에 매핑할 수 있습니다. KeyNamingStrategy에 더해,
Spring은 두 개의 추가적인 ObjectNamingStrategy 구현체를 제공합니다:
bean의 JVM identity를 기반으로 ObjectName을 생성하는 IdentityNamingStrategy와
소스 수준 메타데이터를 사용하여 ObjectName을 얻는 MetadataNamingStrategy입니다.
ObjectName Instances from Properties자신만의 KeyNamingStrategy 인스턴스를 구성하고 bean key를 사용하는 대신
Properties 인스턴스로부터 ObjectName 인스턴스를 읽도록 설정할 수 있습니다.
KeyNamingStrategy는 bean key에 해당하는 key를 가진 entry를 Properties에서
찾으려고 시도합니다.
entry를 찾을 수 없거나 Properties 인스턴스가
null인 경우, bean key 자체가 사용됩니다.
다음 코드는 KeyNamingStrategy에 대한 샘플 설정을 보여줍니다:
1<beans> 2 3 <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter"> 4 <property name="beans"> 5 <map> 6 <entry key="testBean" value-ref="testBean"/> 7 </map> 8 </property> 9 <property name="namingStrategy" ref="namingStrategy"/> 10 </bean> 11 12 <bean id="testBean" class="org.springframework.jmx.JmxTestBean"> 13 <property name="name" value="TEST"/> 14 <property name="age" value="100"/> 15 </bean> 16 17 <bean id="namingStrategy" class="org.springframework.jmx.export.naming.KeyNamingStrategy"> 18 <property name="mappings"> 19 <props> 20 <prop key="testBean">bean:name=testBean1</prop> 21 </props> 22 </property> 23 <property name="mappingLocations"> 24 <value>names1.properties,names2.properties</value> 25 </property> 26 </bean> 27 28</beans>
앞의 예제는 mapping 프로퍼티에 의해 정의된 Properties 인스턴스와
mappings 프로퍼티에 의해 정의된 경로에 위치한 properties 파일로부터 병합된
Properties 인스턴스를 가진 KeyNamingStrategy 인스턴스를 구성합니다. 이
설정에서, testBean bean은 ObjectName으로 bean:name=testBean1을
부여받습니다.
이는 bean key에 해당하는 key를 가진 entry가 Properties 인스턴스에
존재하기 때문입니다.
Properties 인스턴스에서 entry를 찾을 수 없는 경우, bean key 이름이
ObjectName으로 사용됩니다.
MetadataNamingStrategyMetadataNamingStrategy는 각 bean에 대한 ManagedResource
attribute의 objectName 프로퍼티를 사용하여 ObjectName을 생성합니다. 다음 코드는
MetadataNamingStrategy에 대한 설정을 보여줍니다:
1<beans> 2 3 <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter"> 4 <property name="beans"> 5 <map> 6 <entry key="testBean" value-ref="testBean"/> 7 </map> 8 </property> 9 <property name="namingStrategy" ref="namingStrategy"/> 10 </bean> 11 12 <bean id="testBean" class="org.springframework.jmx.JmxTestBean"> 13 <property name="name" value="TEST"/> 14 <property name="age" value="100"/> 15 </bean> 16 17 <bean id="namingStrategy" class="org.springframework.jmx.export.naming.MetadataNamingStrategy"> 18 <property name="attributeSource" ref="attributeSource"/> 19 </bean> 20 21 <bean id="attributeSource" 22 class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource"/> 23 24</beans>
ManagedResource attribute에 대해 objectName이 제공되지 않은 경우,
다음 형식으로 ObjectName이 생성됩니다:
[fully-qualified-package-name]:type=[short-classname],name=[bean-name].
예를 들어, 다음 bean에 대해 생성되는 ObjectName은
com.example:type=MyClass,name=myBean입니다:
1<bean id="myBean" class="com.example.MyClass"/>
management 인터페이스를 정의하기 위해
the annotation-based approach를 사용하기를 원한다면,
MBeanExporter의 편의 서브클래스인 AnnotationMBeanExporter를 사용할 수 있습니다.
이 서브클래스의 인스턴스를 정의할 때는 더 이상
namingStrategy, assembler, attributeSource 설정이 필요하지 않습니다.
항상 표준 Java annotation 기반 메타데이터를 사용하기 때문입니다
(자동 감지도 항상 활성화됩니다). 실제로, MBeanExporter bean을 정의하는 대신,
다음 예제에서 보듯이 @EnableMBeanExport @Configuration annotation 또는 <context:mbean-export/>
요소에 의해 더 단순한 구문이 지원됩니다:
1@Configuration 2@EnableMBeanExport 3public class JmxConfiguration { 4}
1@Configuration 2@EnableMBeanExport 3class JmxConfiguration
1<beans xmlns="http://www.springframework.org/schema/beans" 2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xmlns:context="http://www.springframework.org/schema/context" 4 xsi:schemaLocation="http://www.springframework.org/schema/beans 5 https://www.springframework.org/schema/beans/spring-beans.xsd 6 http://www.springframework.org/schema/context 7 https://www.springframework.org/schema/context/spring-context.xsd"> 8 9 <context:mbean-export/> 10</beans>
필요하다면, 특정 MBean server에 대한 reference를 제공할 수 있으며,
AnnotationMBeanExporter의 프로퍼티인 defaultDomain attribute는
생성된 MBean ObjectName 도메인에 대해 대체 값을 허용합니다. 이는
MetadataNamingStrategy에 대한 이전 section에서 설명한 것처럼
fully qualified 패키지 이름 대신 사용됩니다.
다음 예제가 이를 보여줍니다:
1@Configuration 2@EnableMBeanExport(server="myMBeanServer", defaultDomain="myDomain") 3public class CustomJmxConfiguration { 4}
1@Configuration 2@EnableMBeanExport(server="myMBeanServer", defaultDomain="myDomain") 3class CustomJmxConfiguration
1<beans xmlns="http://www.springframework.org/schema/beans" 2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xmlns:context="http://www.springframework.org/schema/context" 4 xsi:schemaLocation="http://www.springframework.org/schema/beans 5 https://www.springframework.org/schema/beans/spring-beans.xsd 6 http://www.springframework.org/schema/context 7 https://www.springframework.org/schema/context/spring-context.xsd"> 8 9 <context:mbean-export server="myMBeanServer" default-domain="myDomain"/> 10</beans>
⚠️ bean 클래스에서 JMX annotation의 자동 감지와 함께 인터페이스 기반 AOP 프록시를 사용하지 마십시오. 인터페이스 기반 프록시는 target 클래스를 “숨기며”, 이는 JMX 관리 리소스 annotation도 숨깁니다. 따라서, 이 경우에는 target-class 프록시를 사용해야 합니다 (
<aop:config/>,<tx:annotation-driven/>등의 'proxy-target-class' flag를 설정하여). 그렇지 않으면, JMX bean이 시작 시 아무 메시지 없이 무시될 수 있습니다.
Controlling the Management Interface of Your Beans
Using JSR-160 Connectors