'2019/07/23'에 해당되는 글 2건

  1. 2019.07.23 centos7 - python 3.6 / pip3 설치
  2. 2019.07.23 springboot2.16에 swagger2 2.92 연동하기


python3 설치 여부 확인


$ yum search python3

설치할 만만하게 없다면 ius를 추가한다.


$ yum install -y https://centos7.iuscommunity.org/ius-release.rpm


Loaded plugins: fastestmirror


Cannot open: https://centos7.iuscommunity.org/ius-release.rpm. Skipping.


Error: Nothing to do


이럴 때는 rpm을 다운로드하고 바로 설치한다.


$ wget https://centos7.iuscommunity.org/ius-release.rpm --no-check-certificate


$ yum install -y ius-release.rpm


$ sudo yum install -y python36u python36u-libs python36u-devel python36u-pip


$ python3.6 -V

Python 3.6.4




python3로 실행될 수 있도록 링크를 변경한다. 


$ ls -l /bin/python*

lrwxrwxrwx. 1 root root     7  7월  3  2018 /bin/python -> python2

lrwxrwxrwx. 1 root root    14  7월  3  2018 /bin/python-config -> python2-config

lrwxrwxrwx. 1 root root     9  7월  3  2018 /bin/python2 -> python2.7

lrwxrwxrwx. 1 root root    16  7월  3  2018 /bin/python2-config -> python2.7-config

-rwxr-xr-x. 1 root root  7216  4월 11  2018 /bin/python2.7

-rwxr-xr-x. 1 root root  1835  4월 11  2018 /bin/python2.7-config

-rwxr-xr-x  2 root root 11384  5월  3 05:43 /bin/python3.6

lrwxrwxrwx  1 root root    26  7월 23 18:46 /bin/python3.6-config -> /usr/bin/python3.6m-config

-rwxr-xr-x  2 root root 11384  5월  3 05:43 /bin/python3.6m

-rwxr-xr-x  1 root root   173  5월  3 05:42 /bin/python3.6m-config

-rwxr-xr-x  1 root root  3435  5월  3 05:40 /bin/python3.6m-x86_64-config



$ sudo unlink /bin/python

$ sudo ln -s /bin/python3.6 /bin/python3

$ sudo ln -s /bin/python3.6 /bin/python

$ sudo ln -s /bin/pip3.6 /bin/pip

$ ls -l /bin/python*

lrwxrwxrwx  1 root root    14  7월 23 18:47 /bin/python -> /bin/python3.6

lrwxrwxrwx. 1 root root    14  7월  3  2018 /bin/python-config -> python2-config

lrwxrwxrwx. 1 root root     9  7월  3  2018 /bin/python2 -> python2.7

lrwxrwxrwx. 1 root root    16  7월  3  2018 /bin/python2-config -> python2.7-config

-rwxr-xr-x. 1 root root  7216  4월 11  2018 /bin/python2.7

-rwxr-xr-x. 1 root root  1835  4월 11  2018 /bin/python2.7-config

lrwxrwxrwx  1 root root    14  7월 23 18:47 /bin/python3 -> /bin/python3.6

-rwxr-xr-x  2 root root 11384  5월  3 05:43 /bin/python3.6

lrwxrwxrwx  1 root root    26  7월 23 18:46 /bin/python3.6-config -> /usr/bin/python3.6m-config

-rwxr-xr-x  2 root root 11384  5월  3 05:43 /bin/python3.6m

-rwxr-xr-x  1 root root   173  5월  3 05:42 /bin/python3.6m-config

-rwxr-xr-x  1 root root  3435  5월  3 05:40 /bin/python3.6m-x86_64-config



pip3를 설치한다.


$ wget https://bootstrap.pypa.io/get-pip.py


$ sudo -E python get-pip.py


$pip3 -V

pip 19.2 from /usr/lib/python3.6/site-packages/pip (python 3.6)





Posted by 김용환 '김용환'

댓글을 달아 주세요


springboot에 swagger2를 적용하는 예제를 하나 만들었다.

https://github.com/knight76/springboot2-swagger2




* 버전

SpringBoot 2.1 

Swagger2 2.92 

Gradle 




Swagger Config 파일은 다음과 같다. 

@Configuration
@EnableSwagger2
public class SwaggerConfig {
	@Bean
	public Docket api(){
		return new Docket(DocumentationType.SWAGGER_2)
				.groupName("API")
				.select()
				.apis(and(RequestHandlerSelectors.basePackage("com.example.controller")))
				//.apis(RequestHandlerSelectors.any())
				.paths(PathSelectors.any())
		        .build()
				.apiInfo(apiEndPointsInfo());
	}

	public ApiInfo apiEndPointsInfo() {
		return new ApiInfoBuilder().title("Spring Boot REST API with Swagger2")
		                           .description("Language Management REST API")
		                           .contact(new Contact("knight76", "http://knight76.tistory.com", "knight76@gmail.com"))
		                           .license("Apache 2.0")
		                           .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
		                           .version("0.0.1-SNAPSHOT")
		                           .build();
	}
}




RestController의 (Get|Post|..)Mapping 앞에 붙이는 ApiOperation, ApiResponse를 참고한다.

	@ApiOperation(value = "View available cities", response = List.class)
	@ApiResponses(value = {
			@ApiResponse(code = 200, message = "Successfully retrieved list"),
			@ApiResponse(code = 401, message = "You are not authorized to view the resource"),
			@ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
			@ApiResponse(code = 404, message = "The resource you were trying to reach is not found")
	})
	@GetMapping(value = "/cities")
	public List<City> getCities() {
		List<City> cities = cityService.findAll();
		return cities;
	}



중요한 부분은 warning 안보기 위한 gradle 설정이다. 


ext { swagger2Version = '2.9.2' oldSwagger2Version = '1.5.21' } ..

// not showing WARN i.s.m.p.AbstractSerializableParameter : Illegal DefaultValue -1 for parameter type integer // java.lang.NumberFormatException: For input string: "" implementation("io.springfox:springfox-swagger2:${swagger2Version}") { exclude group: 'io.swagger',module: 'swagger-annotations' exclude group: 'io.swagger',module: 'swagger-models' } implementation "io.swagger:swagger-annotations:${oldSwagger2Version}" implementation "io.swagger:swagger-models:${oldSwagger2Version}"


Posted by 김용환 '김용환'

댓글을 달아 주세요