Browse Source
修改application.properties配置 因为spring官方停止维护1.x版本,升级spring 和springboot jar 添加api swagger demopull/2/head
easyscheduler
6 years ago
committed by
GitHub
21 changed files with 253 additions and 30 deletions
@ -0,0 +1,55 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package cn.escheduler.api.configuration; |
||||
|
||||
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
||||
import springfox.documentation.builders.ApiInfoBuilder; |
||||
import springfox.documentation.builders.PathSelectors; |
||||
import springfox.documentation.builders.RequestHandlerSelectors; |
||||
import springfox.documentation.service.ApiInfo; |
||||
import springfox.documentation.spi.DocumentationType; |
||||
import springfox.documentation.spring.web.plugins.Docket; |
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2; |
||||
|
||||
/** |
||||
* |
||||
* swager2 config class <br/> |
||||
* |
||||
*/ |
||||
@Configuration |
||||
@EnableSwagger2 |
||||
@EnableSwaggerBootstrapUI |
||||
public class SwaggerConfig implements WebMvcConfigurer { |
||||
|
||||
@Bean |
||||
public Docket createRestApi() { |
||||
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select() |
||||
.apis(RequestHandlerSelectors.basePackage("cn.escheduler.api.controller")).paths(PathSelectors.any()) |
||||
.build(); |
||||
} |
||||
|
||||
private ApiInfo apiInfo() { |
||||
return new ApiInfoBuilder().title("Easy Scheduler Api Docs").description("Easy Scheduler Api Docs") |
||||
.version("1.0.0").build(); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,52 @@
|
||||
package cn.escheduler.api.configuration; |
||||
|
||||
import java.util.List; |
||||
import java.util.Locale; |
||||
import com.fasterxml.classmate.TypeResolver; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.MessageSource; |
||||
import org.springframework.context.i18n.LocaleContextHolder; |
||||
import org.springframework.core.Ordered; |
||||
import org.springframework.core.annotation.Order; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import io.swagger.annotations.ApiOperation; |
||||
import springfox.documentation.spi.DocumentationType; |
||||
import springfox.documentation.spi.service.OperationBuilderPlugin; |
||||
import springfox.documentation.spi.service.contexts.OperationContext; |
||||
|
||||
|
||||
@Component |
||||
@Order(Ordered.HIGHEST_PRECEDENCE - 10) |
||||
public class SwaggerI18nPlugin implements OperationBuilderPlugin { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SwaggerI18nPlugin.class); |
||||
|
||||
@Autowired |
||||
private MessageSource messageSource; |
||||
|
||||
@Override |
||||
public void apply(OperationContext context) { |
||||
|
||||
Locale locale = LocaleContextHolder.getLocale(); |
||||
|
||||
List<ApiOperation> list = context.findAllAnnotations(ApiOperation.class); |
||||
if (list.size() > 0) { |
||||
for(ApiOperation api : list){ |
||||
context.operationBuilder().summary(messageSource.getMessage(api.value(), null, locale)); |
||||
context.operationBuilder().notes(messageSource.getMessage(api.notes(), null, locale)); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
|
||||
@Override |
||||
public boolean supports(DocumentationType delimiter) { |
||||
return true; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,5 @@
|
||||
welcome=hello, welcome ! |
||||
test=test |
||||
userName=user name |
||||
userPassword=user password |
||||
loginNotes=login notes |
@ -0,0 +1,5 @@
|
||||
welcome=hello, welcome ! |
||||
test=test |
||||
userName=user name |
||||
userPassword=user password |
||||
loginNotes=login notes |
@ -0,0 +1,5 @@
|
||||
welcome=您好,欢迎你! |
||||
test=测试 |
||||
userName=用户名 |
||||
userPassword=用户密码 |
||||
loginNotes=登录xxx |
Loading…
Reference in new issue