1 package {{configPackage}};
3 import com.fasterxml.jackson.databind.ObjectMapper;
4 import com.fasterxml.jackson.databind.SerializationFeature;
6 import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule;
8 import org.springframework.context.annotation.ComponentScan;
9 import org.springframework.context.annotation.Configuration;
10 import org.springframework.context.annotation.PropertySource;
11 import org.springframework.context.annotation.Import;
12 import org.springframework.context.annotation.Bean;
13 import org.springframework.format.FormatterRegistry;
14 import org.springframework.http.converter.HttpMessageConverter;
15 import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
16 import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
17 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
18 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
19 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
21 import org.threeten.bp.Instant;
22 import org.threeten.bp.OffsetDateTime;
23 import org.threeten.bp.ZonedDateTime;
25 import springfox.documentation.swagger2.annotations.EnableSwagger2;
27 import java.util.List;
29 {{>generatedAnnotation}}
31 @ComponentScan(basePackages = "{{apiPackage}}")
33 @EnableSwagger2 //Loads the spring beans required by the framework
34 @PropertySource("classpath:swagger.properties")
35 @Import(SwaggerDocumentationConfig.class)
36 public class SwaggerUiConfiguration implements WebMvcConfigurer {
37 private static final String[] SERVLET_RESOURCE_LOCATIONS = { "/" };
39 private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
40 "classpath:/META-INF/resources/", "classpath:/resources/",
41 "classpath:/static/", "classpath:/public/" };
43 private static final String[] RESOURCE_LOCATIONS;
45 RESOURCE_LOCATIONS = new String[CLASSPATH_RESOURCE_LOCATIONS.length
46 + SERVLET_RESOURCE_LOCATIONS.length];
47 System.arraycopy(SERVLET_RESOURCE_LOCATIONS, 0, RESOURCE_LOCATIONS, 0,
48 SERVLET_RESOURCE_LOCATIONS.length);
49 System.arraycopy(CLASSPATH_RESOURCE_LOCATIONS, 0, RESOURCE_LOCATIONS,
50 SERVLET_RESOURCE_LOCATIONS.length, CLASSPATH_RESOURCE_LOCATIONS.length);
53 private static final String[] STATIC_INDEX_HTML_RESOURCES;
55 STATIC_INDEX_HTML_RESOURCES = new String[RESOURCE_LOCATIONS.length];
56 for (int i = 0; i < STATIC_INDEX_HTML_RESOURCES.length; i++) {
57 STATIC_INDEX_HTML_RESOURCES[i] = RESOURCE_LOCATIONS[i] + "index.html";
62 public void addResourceHandlers(ResourceHandlerRegistry registry) {
63 if (!registry.hasMappingForPattern("/webjars/**")) {
64 registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
66 if (!registry.hasMappingForPattern("/**")) {
67 registry.addResourceHandler("/**").addResourceLocations(RESOURCE_LOCATIONS);
72 public Jackson2ObjectMapperBuilder builder() {
73 Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
75 .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
76 .dateFormat(new RFC3339DateFormat());
81 public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
82 converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
83 super.configureMessageConverters(converters);
87 public void addFormatters(FormatterRegistry registry) {
88 registry.addConverter(new LocalDateConverter("{{#datePattern}}{{datePattern}}{{/datePattern}}{{^datePattern}}yyyy-MM-dd{{/datePattern}}"));
89 registry.addConverter(new LocalDateTimeConverter("{{#dateTimePattern}}{{dateTimePattern}}{{/dateTimePattern}}{{^dateTimePattern}}yyyy-MM-dd'T'HH:mm:ss.SSS{{/dateTimePattern}}"));
93 public ObjectMapper objectMapper(){
94 return builder().build();