私は、swagger-ui を有効にする必要があるスプリング ブート アプリに取り組んでいます。http://localhost:8080/swagger-ui.htmlにアクセスすると、「ベース URL を推測できません ...」というエラー ポップアップが表示されます。
さらに、http://localhost:8080/v2/api-docsが示しています: 行 1 列 1 のエラー: ドキュメントが空です このページのソースコードは json ですが、Content-Type application/xhtml+ としてリクエストされていますxml;文字セット=UTF-8
この原因は、私のカスタム Jackson 構成にあるようです。
@Configuration
public class JacksonConfig {
@Bean
public MappingJackson2XmlHttpMessageConverter mappingJackson2XmlHttpMessageConverter() {
return new MappingJackson2XmlHttpMessageConverter(objectMapper());
}
@Bean
public ObjectMapper objectMapper() {
JacksonXmlModule xmlModule = new JacksonXmlModule();
xmlModule.setDefaultUseWrapper(false);
XmlMapper objectMapper = new XmlMapper(xmlModule);
objectMapper
.registerModule(new ParameterNamesModule())
.registerModule(new Jdk8Module())
.registerModule(new JavaTimeModule());
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE);
objectMapper
.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false)
.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
return objectMapper;
}
}
次の依存関係があります。
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
この問題については、https ://github.com/springfox/springfox/issues/1835 にも記載されています。
私の質問は次のとおりです。swagger-ui を機能させるために、jackson メッセージ コンバーターの優先度を指定するにはどうすればよいですか?