This commit is contained in:
haerong22
2021-02-25 17:40:28 +09:00
parent aa14524b43
commit 88eaa68881
4 changed files with 46 additions and 15 deletions

View File

@@ -81,6 +81,18 @@
<artifactId>springfox-boot-starter</artifactId> <artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version> <version>3.0.0</version>
</dependency> </dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.springfox</groupId>-->
<!-- <artifactId>springfox-boot-starter</artifactId>-->
<!-- <version>3.0.0</version>-->
<!-- </dependency>-->
</dependencies> </dependencies>
<build> <build>

View File

@@ -2,6 +2,10 @@ package com.example.restfulwebservice.config;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo; import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact; import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.DocumentationType;
@@ -16,19 +20,35 @@ import java.util.Set;
@Configuration @Configuration
@EnableSwagger2 @EnableSwagger2
public class SwaggerConfig { public class SwaggerConfig {
private static final Contact DEFAULT_CONTACT = new Contact("Kim", // private static final Contact DEFAULT_CONTACT = new Contact("Kim",
"http://www.joneconsulting.co.kr", "email@naver.com"); // "http://www.joneconsulting.co.kr", "email@naver.com");
private static final ApiInfo DEFAULT_API_INFO = new ApiInfo("Awesome Api Title", // private static final ApiInfo DEFAULT_API_INFO = new ApiInfo("Awesome Api Title",
"My User management REST API service", "1.0", "uri:tos", // "My User management REST API service", "1.0", "uri:tos",
DEFAULT_CONTACT, "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", new ArrayList<>()); // DEFAULT_CONTACT, "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", new ArrayList<>());
private static final Set<String> DEFAULT_PRODUCES_AND_CONSUMES = new HashSet<>( // private static final Set<String> DEFAULT_PRODUCES_AND_CONSUMES = new HashSet<>(
Arrays.asList("application/json", "application/xml")); // Arrays.asList("application/json", "application/xml"));
// @Bean
// public Docket api() {
// return new Docket(DocumentationType.SWAGGER_2)
// .apiInfo(DEFAULT_API_INFO)
// .produces(DEFAULT_PRODUCES_AND_CONSUMES)
// .consumes(DEFAULT_PRODUCES_AND_CONSUMES);
// }
// @Bean
// public Docket apiDocket() {
// return new Docket(DocumentationType.SWAGGER_2)
// .select()
// .apis(RequestHandlerSelectors.any())
// .paths(PathSelectors.any())
// .build();
// }
@Bean @Bean
public Docket api() { public Docket produceApi() {
return new Docket(DocumentationType.SWAGGER_2) return new Docket(DocumentationType.SWAGGER_2).select()
.apiInfo(DEFAULT_API_INFO) .apis(RequestHandlerSelectors.basePackage("com.example.restfulwebservice"))
.produces(DEFAULT_PRODUCES_AND_CONSUMES) .build();
.consumes(DEFAULT_PRODUCES_AND_CONSUMES);
} }
} }

View File

@@ -78,7 +78,7 @@ public class UserJpaController {
post.setUser(user.get()); post.setUser(user.get());
Post savedPost = postRepository.save(post); Post savedPost = postRepository.save(post);
URI location = ServletUriComponentsBuilder. () URI location = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/{id}") .path("/{id}")
.buildAndExpand(savedPost.getId()) .buildAndExpand(savedPost.getId())
.toUri(); .toUri();

View File

@@ -3,7 +3,7 @@ server:
logging: logging:
level: level:
org.springframework: DEBUG org.springframework: INFO
spring: spring:
messages: messages:
@@ -25,7 +25,6 @@ spring:
username: sa username: sa
password: password:
management: management:
endpoints: endpoints:
web: web: