2017-01-22 51 views
1

我想測試Microsoft Azure的Application Insight工具。 出於這個原因,我參加了一個Spring應用程序,jpetshop(https://github.com/mybatis/jpetstore-6),我試圖建立的Application Insight可以在它上面這個指南:https://docs.microsoft.com/en-us/azure/application-insights/app-insights-java-get-startedJPetShop和Azure Application Insight

我加入了Maven的依賴和倉庫,而且由於在Eclipse中,我使用InstrumentationKey創建了ApplicationInsights.xml文件。唯一不確定的是如何添加HTTP應用程序。

我修改這樣的web.xml文件:

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    version="2.5"> 
    <display-name>JPetStore</display-name> 
    <description>Online Pet Store Sample Application</description> 
    <context-param> 
     <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name> 
     <param-value>StripesResources</param-value> 
    </context-param> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
    <filter> 
     <display-name>Stripes Filter</display-name> 
     <filter-name>StripesFilter</filter-name> 
     <filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class> 
     <init-param> 
      <param-name>ActionResolver.Packages</param-name> 
      <param-value>org.mybatis.jpetstore.web</param-value> 
     </init-param> 
     <init-param> 
      <param-name>Extension.Packages</param-name> 
      <param-value>net.sourceforge.stripes.integration.spring</param-value> 
     </init-param> 

     <init-param> 
      <param-name>ApplicationInsightsRequestNameInterceptor</param-name> 
      <param-value>com.microsoft.applicationinsights.web.struts.RequestNameInterceptor</param-value> 
     </init-param>  

    </filter> 
    <filter-mapping> 
     <filter-name>StripesFilter</filter-name> 
     <servlet-name>StripesDispatcher</servlet-name> 
     <dispatcher>REQUEST</dispatcher> 
    </filter-mapping> 
    <servlet> 
     <servlet-name>StripesDispatcher</servlet-name> 
     <servlet-class>net.sourceforge.stripes.controller.DispatcherServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>StripesDispatcher</servlet-name> 
     <url-pattern>*.action</url-pattern> 
    </servlet-mapping> 
</web-app> 

不過,如果我更改爲先導所示的過濾器映射器領域中,應用程序不工作了。

由於jpetshop應用程序使用Spring框架,我也修改了* -servlet.xml文件。但是,該文件不在此項目中。

您知道如何才能使此應用程序上的Azure Application Insight工作? 謝謝

回答

1

我想你錯過,你需要定義ApplicationInsights的過濾器部分:

<filter> 
    <filter-name>ApplicationInsightsWebFilter</filter-name> 
    <filter-class> 
    com.microsoft.applicationinsights.web.internal.WebRequestTrackingFilter 
    </filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>ApplicationInsightsWebFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping>