Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
fdf7f6b7
W
whatsmars
项目概览
武汉红喜
/
whatsmars
通知
3
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
fdf7f6b7
编写于
8月 02, 2017
作者:
S
shenhongxi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
swagger
上级
3427c506
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
173 addition
and
5 deletion
+173
-5
whatsmars-spring-boot/README.md
whatsmars-spring-boot/README.md
+2
-1
whatsmars-spring-boot/pom.xml
whatsmars-spring-boot/pom.xml
+33
-0
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/common/ProfileUtils.java
...com/itlong/whatsmars/spring/boot/common/ProfileUtils.java
+49
-0
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/config/SwaggerConfig.java
...om/itlong/whatsmars/spring/boot/config/SwaggerConfig.java
+84
-0
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/controller/SampleController.java
...ng/whatsmars/spring/boot/controller/SampleController.java
+3
-2
whatsmars-spring-boot/src/main/resources/application-dev.properties
...spring-boot/src/main/resources/application-dev.properties
+1
-1
whatsmars-spring-boot/src/main/resources/application.properties
...ars-spring-boot/src/main/resources/application.properties
+1
-1
未找到文件。
whatsmars-spring-boot/README.md
浏览文件 @
fdf7f6b7
启动后访问 http://localhost/
<br
/>
启动后访问 http://localhost:8081/
<br
/>
swagger http://localhost:8081/swagger-ui.html
mvn clean package -DskipTests
<br
/>
得到的jar包中的MANIFEST.MF其中几行:
<br
/>
...
...
whatsmars-spring-boot/pom.xml
浏览文件 @
fdf7f6b7
...
...
@@ -14,6 +14,9 @@
<!-- The main class to start by executing java -jar -->
<start-class>
com.itlong.whatsmars.spring.boot.App
</start-class>
<motan.version>
0.1.1
</motan.version>
<springfox.swagger2.version>
2.5.0
</springfox.swagger2.version>
<google.gson.version>
2.8.0
</google.gson.version>
<google.guava.version>
20.0
</google.guava.version>
</properties>
<parent>
...
...
@@ -117,6 +120,36 @@
<version>
1.0.31
</version>
</dependency>
<!-- Swagger-ui -->
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<version>
2.5.0
</version>
<exclusions>
<exclusion>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
<version>
${springfox.swagger2.version}
</version>
</dependency>
<!-- google -->
<dependency>
<groupId>
com.google.code.gson
</groupId>
<artifactId>
gson
</artifactId>
<version>
${google.gson.version}
</version>
</dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
${google.guava.version}
</version>
</dependency>
</dependencies>
...
...
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/common/ProfileUtils.java
0 → 100644
浏览文件 @
fdf7f6b7
package
com.itlong.whatsmars.spring.boot.common
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.core.env.Environment
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
/**
* Created by shenhongxi on 2017/8/2.
*/
@Component
public
class
ProfileUtils
implements
InitializingBean
{
@Autowired
private
Environment
env
;
private
static
final
String
PROFILE_PROD
=
"prod"
;
private
static
final
String
PROFILE_TEST
=
"test"
;
private
static
final
String
PROFILE_DEV
=
"dev"
;
private
static
List
<
String
>
profiles
=
Collections
.
unmodifiableList
(
new
ArrayList
<
String
>());
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
profiles
=
Collections
.
unmodifiableList
(
Arrays
.
asList
(
env
.
getActiveProfiles
()));
}
public
static
boolean
isProd
()
{
return
profiles
.
contains
(
PROFILE_PROD
);
}
public
static
boolean
isTest
()
{
return
profiles
.
contains
(
PROFILE_TEST
);
}
public
static
boolean
isDev
()
{
return
profiles
.
contains
(
PROFILE_DEV
);
}
public
static
List
<
String
>
getProfiles
()
{
return
profiles
;
}
}
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/config/SwaggerConfig.java
0 → 100644
浏览文件 @
fdf7f6b7
package
com.itlong.whatsmars.spring.boot.config
;
import
com.fasterxml.classmate.TypeResolver
;
import
com.itlong.whatsmars.spring.boot.App
;
import
com.itlong.whatsmars.spring.boot.common.ProfileUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Profile
;
import
org.springframework.core.env.Environment
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.context.request.async.DeferredResult
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.schema.WildcardType
;
import
springfox.documentation.service.ApiInfo
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.swagger.web.UiConfiguration
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
import
static
springfox
.
documentation
.
schema
.
AlternateTypeRules
.
newRule
;
@Profile
({
"dev"
,
"test"
})
@ConditionalOnClass
(
EnableSwagger2
.
class
)
@EnableSwagger2
@Configuration
public
class
SwaggerConfig
{
@Autowired
private
TypeResolver
typeResolver
;
@Autowired
private
Environment
env
;
@Bean
public
Docket
swaggerSpringMvcPlugin
()
{
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
groupName
(
"business-api"
)
.
select
()
.
apis
(
RequestHandlerSelectors
.
basePackage
(
App
.
class
.
getPackage
().
getName
()))
.
paths
(
PathSelectors
.
any
())
.
build
()
.
pathMapping
(
"/"
)
.
genericModelSubstitutes
(
ResponseEntity
.
class
)
.
alternateTypeRules
(
newRule
(
typeResolver
.
resolve
(
DeferredResult
.
class
,
typeResolver
.
resolve
(
ResponseEntity
.
class
,
WildcardType
.
class
)),
typeResolver
.
resolve
(
WildcardType
.
class
)))
// .enableUrlTemplating(true)
.
useDefaultResponseMessages
(
true
)
.
forCodeGeneration
(
false
)
.
host
(
host
())
.
apiInfo
(
apiInfo
());
}
@Bean
public
UiConfiguration
uiConfig
()
{
return
new
UiConfiguration
(
"validatorUrl"
,
// url
"none"
,
// docExpansion => none | list
"alpha"
,
// apiSorter => alpha
"schema"
,
// defaultModelRendering => schema
UiConfiguration
.
Constants
.
DEFAULT_SUBMIT_METHODS
,
false
,
// enableJsonEditor => true | false
true
);
// showRequestHeaders => true | false
}
private
String
host
()
{
String
port
=
env
.
getProperty
(
"server.port"
);
if
(
ProfileUtils
.
isDev
())
{
return
"localhost:"
+
port
;
}
return
"test.toutiao.im"
;
}
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
.
title
(
"Toutiao API"
)
.
description
(
"用于调试Toutiao RestAPI,只在test/dev中放开,prod中关闭"
)
.
version
(
"0.1"
)
.
build
();
}
}
\ No newline at end of file
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/controller/SampleController.java
浏览文件 @
fdf7f6b7
...
...
@@ -10,6 +10,7 @@ import org.springframework.context.i18n.LocaleContextHolder;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.servlet.LocaleResolver
;
import
org.springframework.web.servlet.i18n.AbstractLocaleResolver
;
...
...
@@ -49,7 +50,7 @@ public class SampleController {
@RequestMapping
(
"/changeLang"
)
@ResponseBody
public
String
changeLang
(
HttpServletRequest
request
,
HttpServletResponse
response
,
String
lang
){
public
String
changeLang
(
HttpServletRequest
request
,
HttpServletResponse
response
,
@RequestParam
String
lang
){
LocaleResolver
localeResolver
=
RequestContextUtils
.
getLocaleResolver
(
request
);
if
(
"zh"
.
equals
(
lang
))
{
// request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, new Locale("zh", "CN"));
...
...
@@ -61,7 +62,7 @@ public class SampleController {
return
"lang:"
+
LocaleContextHolder
.
getLocale
().
getLanguage
();
}
@RequestMapping
(
"/"
)
@RequestMapping
(
value
=
"/"
,
method
=
RequestMethod
.
GET
)
public
String
home
(
Map
<
String
,
Object
>
map
)
{
System
.
out
.
println
(
LocaleUtils
.
isEnLocale
());
map
.
put
(
"hello"
,
"Hi, boy!"
);
...
...
whatsmars-spring-boot/src/main/resources/application-dev.properties
浏览文件 @
fdf7f6b7
server.port
:
80
server.port
:
80
81
spring.session.store-type
=
redis
server.session.timeout
=
14400
...
...
whatsmars-spring-boot/src/main/resources/application.properties
浏览文件 @
fdf7f6b7
...
...
@@ -2,7 +2,7 @@
#spring.profiles.active=dev
spring.profiles.active
=
test
spring.profiles.active
=
dev
spring.thymeleaf.cache
=
false
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录