2017-09-07 5 views
2

私はSpring Boot Rest Webサービスを持っています。私はまた、静的コンテンツをswagger-uiとともにsrc/main/resources/static.swagger-uiに追加しました。私は私のドキュメントにアクセスできます。ApplicationInsightsは、静的コンテンツのデフォルトのSpringブート設定を破ります。

デフォルトでは、SimpleUrlHandlerMappingは起動時に静的コンテンツに自動的にリクエストをマッピングします。

... 
2017-09-07 15:41:21.144 INFO 6912 --- [localhost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 
2017-09-07 15:41:21.144 INFO 6912 --- [localhost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 
2017-09-07 15:41:21.212 INFO 6912 --- [localhost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 
... 

私はこれは何とかもはや機能しない静的なコンテンツへのマッピングとしてSimpleUrlHandlerMappingを壊している

私のGradleファイルに
... part of my gradle file 
// Application Insight related jar - required for telemetrics and loggers 
compile("com.microsoft.azure:applicationinsights-web:${aiWeb}") 
compile("com.microsoft.azure:applicationinsights-logging-logback:${aiLogback}") 
... 

を応用洞察への参照を追加しました。

どのように修正するのですか?

  • springBootVersion = 1.5.3.RELEASE
  • springSecurityVersion = 4.2.1.RELEASE
  • aiWeb = 1.0.9 aiLogback = 1.0:私はおそらく...手動

    私のスタックをマッパーを追加することができます0.6

答えて

0

デバッグの一日後、私は、私は根本的な原因(確認のための回避策)

を見つけたと思いますSpring Bootのdocumentationによると、Spring MVCは自動的に設定されます。これには、静的コンテンツの構成が含まれます。

我々はapplicationinsights.web可能パッケージを見てみた場合InterceptorRegistry

package com.microsoft.applicationinsights.web.spring.internal; 

import org.springframework.context.annotation.Configuration; 
import org.springframework.web.servlet.config.annotation.EnableWebMvc; 
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 
import com.microsoft.applicationinsights.web.spring.RequestNameHandlerInterceptorAdapter; 

/** 
* This class registers the RequestNameHandlerInterceptorAdapter to the interceptors registry. 
* The registration enables the interceptor to extract the http request's controller and action names. 
*/ 
@EnableWebMvc 
@Configuration 
public class InterceptorRegistry extends WebMvcConfigurerAdapter { 

    @Override 
    public void addInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry) { 
     registry.addInterceptor(new RequestNameHandlerInterceptorAdapter()); 
    } 
} 

というクラスがあり、これはドキュメントが言うことである:

あなたは春ブーツMVCを維持したい場合(インターセプタ、フォーマッタ、ビュー コントローラなど)を追加する場合は、タイプの@Configurationクラスを独自に追加することができますWebMvcConfigurerAdapterが、なし

@EnableWebMvc

は、だから、クラスが自動設定機能を破る @EnableWebMvc注釈が含まれているとして、パッケージにバグがあるようです。

私はこの注釈なしでそのライブラリを再コンパイルしていないので、このタグを削除するとこの問題を解決できるかどうかはわかりません。私がしたのは、手動でマッピングを追加することです。

@Configuration 
public class MvcConfig extends WebMvcConfigurerAdapter { 
    @Override 
    public void addResourceHandlers(ResourceHandlerRegistry registry) { 
     registry 
       .addResourceHandler("/swagger-ui/**") 
       .addResourceLocations("classpath:/static/swagger-ui/"); 
     super.addResourceHandlers(registry); 
    } 
} 
関連する問題