Javamelody monitoring Spring, struts

Source: Internet
Author: User

Read Catalogue

    • Struts Monitoring

    • Spring Monitoring

> Here's how to monitor struts and spring.

hand code is not easy, reproduced please specify: xingoo

Since spring's theory is not solid, monitoring spring is also dependent on Sring's aspect-oriented AOP technology, so while the configuration is based on official documentation, it still does not have access to monitoring data. Let's talk about the simple struts monitoring here.

Back to Top

Struts Monitoring

The monitoring of struts is relatively simple, as long as you follow the steps below, there must be no problem.

 The first step is to import the necessary jar packages, which are already mentioned in the previous jar package.

One is Javamelody.jar, the other is Jrobin-x.jar.

  Second step, you need to add a monitor filter in Web. xml

1 <filter> 2 <filter-name>monitoring</filter-name> 3 <filter-class> Net.bull.javamelody.monitoringfilter</filter-class> 4 5 <init-param> 6 <param-name>log</param- Name> 7 <param-value>true</param-value> 8 </init-param> 9 </filter>10 <filter-mapping >11 <filter-name>monitoring</filter-name>12 <url-pattern>/*</url-pattern>13 </ filter-mapping>14 <listener>16 <listener-class> net.bull.javamelody.sessionlistener</ Listener-class>17 </listener>

Of course, don't forget struts ' own filters.

1 <filter> 2 <filter-name>struts</filter-name> 3 <filter-class>org.apache.struts2.dispatche R.filterdispatcher</filter-class> 4 5 <init-param> 6 <PARAM-NAME>STRUTS.ACTION.EXTENSION</PA Ram-name> 7 <param-value>action</param-value> 8 </init-param> 9 </filter>10 <fil Ter-mapping>11 <filter-name>struts</filter-name>12 <url-pattern>/*</url-pattern>13 < ;/filter-mapping>

  The third step is to add the default package in Struts.xml, which provides the default interceptor

  1 <package name=  "Default"  extends = "Struts-default,json-default"   > 2   <!--  Register interceptors or interceptor stacks with the STRUTS2 framework, typically for custom interceptors or interceptor stacks registration  --> 3    <interceptors> 4    <interceptor name = "Monitoring"  class = "Net.bull.javamelody.StrutsInterceptor"  /> 5    < interceptor-stack name = "Mystack"  > 6     <interceptor-ref  name = "Monitoring"  /> 7     <interceptor-ref name  = "Defaultstack"  /> 8    </interceptor-stack> 9    </interceptors>10   <!--Set the default interceptor information to be applied to all actions within the entire package range  -->11    <default-interceptor-ref name = "Mystack"  />12     </ Package> 

Other packages, such as sttuts, inherit the default package.

 1 <package name= "test"  extends= "Default" > 2          <action name= "Login"  class= "com.test.LoginAction" > 3              <result name= "Error" >/error.jsp </result> 4             <result  name= "Success" >/success.jsp</result> 5          </action> 6  7         <action  name= "Search"  class= "com.test.SearchAction" > 8              <result name= "Error" >/error.jsp</result> 9              <result name= "Success" >/ Searchsuccess.jsp</result>10         </action>11         12         <action name= "Hibernatetest"  class= "Com.test.TestHibernate" >13              <result name= "Error" >/error.jsp</result>14              <result name= "Success" >/hibernateSuccess.jsp</result>15          </action>16 17     </ Package>

The above three steps, even if the configuration is finished.

If monitoring events are not triggered, such as clicking on something to respond to a jump, using struts, then the data is not monitored. Although there is a display of the corresponding picture, but the data on the image is 0,nan or the table below is empty, these are not triggered to listen to the event of the cause.

Back to Top

Spring Monitoring

Javamelody the monitoring of spring is at the method level, we can monitor a method of a class, so we need to use the pointcut in AOP to listen.

Here's a look at the main monitoring configuration:

  The first step is still to import the necessary jar package, which says two, no longer repeat.

  The second step is to load the monitoring-spring.xml and our own applicationcontext.xml configuration files.

If you want to read the spring configuration file while loading Web. XML, you need to implement a listener

1 <listener>2 <listener-class>3 Org.springframework.web.context.ContextLoaderListener4 </listener-class>5 </listener>

Then in Web. XML, add the spring file path. Use this context parameter to set the

1 <context-param>2 <param-name> contextconfiglocation</param-name>3 <param-value>4              Classpath:net/bull/javamelody/monitoring-spring.xml5/web-inf/classes/bean.xml6 </param-value>7 </context-param>

The first line above defines the spring configuration file for the monitoring application, which is our own spring configuration file.

  The third step, through the regular expression, the location method

1 <bean id= "facademonitoringadvisor" class= "Net.bull.javamelody.MonitoringSpringAdvisor" >2 <property name= "Pointcut" >3 <bean class= "org.springframework.aop.support.JdkRegexpMethodPointcut" >4 <property name= "p Attern "value=" com.test.*.* "/>5 </bean>6 </property>7 </bean>

This is mainly the use of jdkregexpmethodpointcut, which is the regular expression of the business method of positioning. The following parameters may be pattern or patterns, parameter

    com.test.*.* means all methods that correspond to all classes under the Com.test package

    Com.test.*.doget means a method called Doget that corresponds to all classes under the Com.test package.

    . *test.* means all methods for all classes that end with Test

For specific configuration details, you will also need to learn about the use of the Pointcut pointcut in AOP. If not, take a look at the relevant knowledge.

Then add this interceptor for the bean you want to monitor:

1 <bean id= "Proxyfactorybean" class= "Org.springframework.aop.framework.ProxyFactoryBean" > 2 <property name= "Target" > 3 <ref bean= "Computer"/> 4 </property> 5 <property name= "Interceptornames" > 6 &L T;list> 7 <value>facadeMonitoringAdvisor</value> 8 </list> 9 </property>10 </bean& Gt

This will automatically call the Interceptor Interceptornames when using Proxyfactorybean, navigate to the method in Facademonitoringadvisor, and start before and after the method Net.bull.javamelody.MonitoringSpringAdvisor, to monitor the information.

The corresponding aspect of the programming code here is also directly attached, interested can run the experiment, mainly to understand the idea, you can monitor their interest in the business.

View Code

  

I've been working on it for a day and a half, and I haven't been monitoring the data because the interceptor has not been triggered since the default interceptor was configured. So there is no call to this monitoring class, and of course no monitoring information appears.

Summing up, or because you do not understand the principles of spring AOP, will later fill the relevant learning spring.


Javamelody monitoring Spring, struts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.