├── .classpath
├── .gitignore
├── .project
├── .settings
├── org.eclipse.core.resources.prefs
├── org.eclipse.jdt.core.prefs
└── org.eclipse.m2e.core.prefs
├── README.md
├── arc.png
├── pom.xml
├── qrcode_for_gh_28fb95c9c24c_258.jpg
└── src
├── main
├── docker
│ └── Dockerfile
├── java
│ └── com
│ │ └── growithus
│ │ └── demo
│ │ ├── WebAPIStartup.java
│ │ ├── aop
│ │ ├── AuthorizationAspect.java
│ │ ├── RateLimiterAspect.java
│ │ ├── WebLogAspect.java
│ │ └── WhitelistAspect.java
│ │ ├── config
│ │ ├── MyExceptionHandler.java
│ │ └── Swagger2Config.java
│ │ └── controller
│ │ └── APITestController.java
└── resources
│ ├── application-dev.yml
│ ├── application-pro.yml
│ ├── application-test.yml
│ ├── application.yml
│ └── log4j.properties
└── test
└── java
└── com
└── growithus
└── demo
└── ApplicationTest.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | web-api-demo
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.m2e.core.maven2Nature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/main/resources=UTF-8
4 | encoding//src/test/java=UTF-8
5 | encoding//src/test/resources=UTF-8
6 | encoding/=UTF-8
7 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.8
6 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ###简介:
2 |
3 | 面向移动端(手机App,公众号,小程序.....)提供的API服务脚手架开发框架,项目代码:
4 |
5 | >[https://github.com/backkoms/web-api-demo](https://github.com/backkoms/web-api-demo)
6 | >
7 | >[https://gitee.com/Kristening/web-api-demo](https://gitee.com/Kristening/web-api-demo)
8 |
9 | 可用于实施基于Dubbo的分布式/微服务项目开发、重构等等,下载到本地,包名稍做调整即可关注业务进行API开发。
10 | 
11 |
12 | ###项目定位:
13 | >面向移动端提供API服务,不处理具体业务逻辑,需调用后端的[Dubbo]服务处理。可用于从大单体应用中解耦,实施前后端分离部署、分层部署。
14 |
15 | >可配合web-service-demo使用。
16 | APITestController.java文件中DemoService接口依赖web-service-demo中的web-service-i模块,若暂无需求可将其注释掉。
17 |
18 | ###技术组件:
19 | - Spring Boot 2.0.4.RELEASE
20 | - Swagger 2.6.1
21 | - Dubbo-spring-boot-starter 0.2.0
22 | - Lombok 1.16
23 |
24 | ###提供功能:
25 | - Swagger集成,对外提供友好的API界面
26 | - 基于profiles提供的多环境打包构建
27 | - 集成Log4j日志服务,替代原有的logging日志组件
28 | - 集成lombok,简化实体的编写
29 | - 结合AOP,实现简单的安全验证,如接口验签、接口速率限制、黑白名单(结合具体业务场景实现)
30 | - 集成Docker构建插件,可打包成Docker镜像运行
31 |
32 | >注:web-service-demo的Github项目地址:
33 | >
34 | >https://github.com/backkoms/web-service-demo
35 | >
36 | https://gitee.com/Kristening/web-service-demo
37 |
38 | >基于SpringBoot2和Dubbo的微服务开发框架,已集成Rabbitmq、Redis、Mybatis。
39 |
40 | #联系我
41 |
42 | 
43 |
44 | 微信号:Dqango
45 |
46 |
47 | #SpringCloud微服务实战实例
48 |
49 | [https://github.com/backkoms/simplemall](https://github.com/backkoms/simplemall)
50 |
51 | [源码解读](https://xiaozhuanlan.com/msa-practice)
52 |
--------------------------------------------------------------------------------
/arc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maventalker/web-api-demo/33feb5025f58ef0cbb988a94d3016167ea64352d/arc.png
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.growithus.demo
5 | web-api-demo
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | org.springframework.boot
10 | spring-boot-starter-parent
11 | 2.0.4.RELEASE
12 |
13 |
14 |
15 | 1.8
16 |
17 | true
18 |
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-web
24 |
25 |
26 | log4j-over-slf4j
27 | org.slf4j
28 |
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-starter-logging
38 |
39 |
40 |
41 |
42 | org.springframework.boot
43 | spring-boot-starter-log4j
44 | 1.3.1.RELEASE
45 |
46 |
47 | org.springframework.boot
48 | spring-boot-starter-test
49 | test
50 |
51 |
52 | org.springframework.boot
53 | spring-boot-devtools
54 | true
55 |
56 |
57 |
58 | org.springframework.boot
59 | spring-boot-starter-aop
60 |
61 |
62 |
63 |
64 | io.springfox
65 | springfox-swagger2
66 | 2.6.1
67 |
68 |
69 | io.springfox
70 | springfox-swagger-ui
71 | 2.6.1
72 |
73 |
74 | com.alibaba.boot
75 | dubbo-spring-boot-starter
76 | 0.2.0
77 |
78 |
79 | org.projectlombok
80 | lombok
81 |
82 |
83 |
84 |
85 | com.alibaba
86 | fastjson
87 | 1.2.31
88 |
89 |
90 | com.growithus.service.itf
91 | web-service-i
92 | 0.0.1-SNAPSHOT
93 |
94 |
95 |
96 |
97 |
98 | fenbei-customer-api
99 |
100 |
101 | org.springframework.boot
102 | spring-boot-maven-plugin
103 |
104 |
105 |
106 |
107 | com.spotify
108 | docker-maven-plugin
109 | 1.0.0
110 |
111 | ${docker.image.prefix}/${project.artifactId}
112 | src/main/docker
113 |
114 |
115 | /
116 | ${project.build.directory}
117 | ${project.build.finalName}.jar
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/qrcode_for_gh_28fb95c9c24c_258.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maventalker/web-api-demo/33feb5025f58ef0cbb988a94d3016167ea64352d/qrcode_for_gh_28fb95c9c24c_258.jpg
--------------------------------------------------------------------------------
/src/main/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8-jdk-alpine
2 | VOLUME /tmp
3 | ADD web-api-demo.jar app.jar
4 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
--------------------------------------------------------------------------------
/src/main/java/com/growithus/demo/WebAPIStartup.java:
--------------------------------------------------------------------------------
1 | package com.growithus.demo;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
7 |
8 | /**
9 | * 启动类
10 | *
11 | * @author guooo 公众号:growithus 2018年11月2日 下午10:43:42
12 | *
13 | */
14 | @SpringBootApplication
15 | @EnableDubbo
16 | public class WebAPIStartup {
17 |
18 | public static void main(String[] args) {
19 | SpringApplication.run(WebAPIStartup.class, args);
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/growithus/demo/aop/AuthorizationAspect.java:
--------------------------------------------------------------------------------
1 | package com.growithus.demo.aop;
2 |
3 | import org.apache.log4j.Logger;
4 | import org.aspectj.lang.ProceedingJoinPoint;
5 | import org.aspectj.lang.annotation.Around;
6 | import org.aspectj.lang.annotation.Aspect;
7 | import org.aspectj.lang.annotation.Pointcut;
8 | import org.springframework.core.annotation.Order;
9 | import org.springframework.stereotype.Component;
10 |
11 |
12 | /**
13 | * ClassName:AuthorizationAspect
14 | * Function: 请求参数合法性验证
15 | * Date: 2018年10月16日 上午10:44:35
16 | *
17 | * @author guooo 公众号:growithus
18 | * @version
19 | * @since JDK 1.6
20 | * @see
21 | */
22 | @Aspect
23 | @Order(5)
24 | @Component
25 | public class AuthorizationAspect {
26 | private Logger logger = Logger.getLogger(AuthorizationAspect.class);
27 |
28 | // @Autowired
29 | // AuthorizeService authorizeService;
30 |
31 | @Pointcut("execution(public * com.growithus.demo.controller.*.*.* (..))")
32 | public void authorizationAspect() {
33 |
34 | }
35 |
36 | @Around("authorizationAspect()")
37 | public String dobefore(ProceedingJoinPoint joinPoint) {
38 | // BizResult bizResult = new BizResult();
39 | // RequestAttributes ra = RequestContextHolder.getRequestAttributes();
40 | // ServletRequestAttributes sra = (ServletRequestAttributes) ra;
41 | // HttpServletRequest request = sra.getRequest();
42 | // try {
43 | // if (!authorizeService.argsCheck(request)) {
44 | // logger.warn("验签错误!");
45 | // bizResult.setReq(ReqResultCode.REQ_RESULT_CODE_ILLEGAL_SIGN);
46 | // } else {
47 | // try {
48 | // return (BizResult) joinPoint.proceed();
49 | // } catch (Throwable e) {
50 | // e.printStackTrace();
51 | // }
52 | // }
53 | // } catch (BusinessException e) {
54 | // e.printStackTrace();
55 | // }
56 | return null;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/growithus/demo/aop/RateLimiterAspect.java:
--------------------------------------------------------------------------------
1 |
2 | package com.growithus.demo.aop;
3 |
4 | import org.aspectj.lang.annotation.Aspect;
5 | import org.springframework.core.annotation.Order;
6 | import org.springframework.stereotype.Component;
7 |
8 | /**
9 | * ClassName:RateLimiterAspect
10 | * Function: 接口限流
11 | * Date: 2018年10月16日 上午10:44:12
12 | *
13 | * @author guooo 公众号:growithus
14 | * @version
15 | * @since JDK 1.6
16 | * @see
17 | */
18 | @Aspect
19 | @Order(6)
20 | @Component
21 | public class RateLimiterAspect {
22 | /**
23 | * 思路:结合redis,将每个接口作为key存进去,进行自增操作,自定个时间间隔作为数据的有效时限,时间间隔内达到数量上限,即不受理接口请求。
24 | */
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/growithus/demo/aop/WebLogAspect.java:
--------------------------------------------------------------------------------
1 | package com.growithus.demo.aop;
2 |
3 | import java.util.Arrays;
4 |
5 | import javax.servlet.http.HttpServletRequest;
6 |
7 | import org.aspectj.lang.JoinPoint;
8 | import org.aspectj.lang.ProceedingJoinPoint;
9 | import org.aspectj.lang.annotation.AfterReturning;
10 | import org.aspectj.lang.annotation.Around;
11 | import org.aspectj.lang.annotation.Aspect;
12 | import org.aspectj.lang.annotation.Before;
13 | import org.aspectj.lang.annotation.Pointcut;
14 | import org.slf4j.Logger;
15 | import org.slf4j.LoggerFactory;
16 | import org.springframework.core.annotation.Order;
17 | import org.springframework.stereotype.Component;
18 | import org.springframework.web.context.request.RequestContextHolder;
19 | import org.springframework.web.context.request.ServletRequestAttributes;
20 |
21 | /**
22 | * 日志记录
23 | *
24 | * @author guooo 公众号:growithus 2018年10月25日 下午2:05:16
25 | *
26 | */
27 | @Aspect
28 | @Component
29 | @Order(0)
30 | public class WebLogAspect {
31 |
32 | private static final Logger logger = LoggerFactory.getLogger(WebLogAspect.class);
33 |
34 | @Pointcut("execution( * com.growithus..controller.*.*(..))") // 两个..代表所有子目录,最后括号里的两个..代表所有参数
35 | public void logPointCut() {
36 | }
37 |
38 | @Before("logPointCut()")
39 | public void doBefore(JoinPoint joinPoint) throws Throwable {
40 | // 接收到请求,记录请求内容
41 | ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
42 | HttpServletRequest request = attributes.getRequest();
43 |
44 | // 记录下请求内容
45 | logger.info("请求地址 : " + request.getRequestURL().toString());
46 | logger.info("HTTP METHOD : " + request.getMethod());
47 | // 获取真实的ip地址
48 | // logger.info("IP : " + IPAddressUtil.getClientIpAddress(request));
49 | logger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "."
50 | + joinPoint.getSignature().getName());
51 | logger.info("参数 : " + Arrays.toString(joinPoint.getArgs()));
52 | // loggger.info("参数 : " + joinPoint.getArgs());
53 |
54 | }
55 |
56 | @AfterReturning(returning = "ret", pointcut = "logPointCut()") // returning的值和doAfterReturning的参数名一致
57 | public void doAfterReturning(Object ret) throws Throwable {
58 | // 处理完请求,返回内容(返回值太复杂时,打印的是物理存储空间的地址)
59 | logger.debug("返回值 : " + ret);
60 | }
61 |
62 | @Around("logPointCut()")
63 | public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
64 | long startTime = System.currentTimeMillis();
65 | Object ob = pjp.proceed();// ob 为方法的返回值
66 | logger.info("耗时 : " + (System.currentTimeMillis() - startTime));
67 | return ob;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/com/growithus/demo/aop/WhitelistAspect.java:
--------------------------------------------------------------------------------
1 |
2 | package com.growithus.demo.aop;
3 |
4 | import javax.servlet.http.HttpServletRequest;
5 |
6 | import org.apache.log4j.Logger;
7 | import org.aspectj.lang.ProceedingJoinPoint;
8 | import org.aspectj.lang.annotation.Around;
9 | import org.aspectj.lang.annotation.Aspect;
10 | import org.aspectj.lang.annotation.Pointcut;
11 | import org.springframework.core.annotation.Order;
12 | import org.springframework.stereotype.Component;
13 |
14 | /**
15 | * ClassName:WhitelistAspect
16 | * Function: 白名单限制
17 | * Date: 2018年10月16日 上午10:43:48
18 | *
19 | * @author guooo 公众号:growithus
20 | * @version
21 | * @since JDK 1.6
22 | * @see
23 | */
24 | @Aspect
25 | @Component
26 | @Order(2)
27 | public class WhitelistAspect {
28 | private Logger logger = Logger.getLogger(WhitelistAspect.class);
29 |
30 | // @Autowired
31 | // RedisSpecCacheService redisSpecCacheService;
32 |
33 | // @Autowired
34 | // AuthorizeService authorizeService;
35 |
36 | @Pointcut("execution(public * com.growithus.demo.controller.*.*.* (..))")
37 | public void whitelistAspect() {
38 |
39 | }
40 |
41 | /**
42 | *
43 | * dobefore:IP白名单验证
44 | *
45 | * @author pan
46 | * @param joinPoint
47 | * @since JDK 1.6
48 | */
49 | @Around("whitelistAspect()")
50 | public String dobefore(ProceedingJoinPoint joinPoint) {
51 | // BizResult bizResult = new BizResult();
52 | // RequestAttributes ra = RequestContextHolder.getRequestAttributes();
53 | // ServletRequestAttributes sra = (ServletRequestAttributes) ra;
54 | // HttpServletRequest request = sra.getRequest();
55 | // String ip = getIpAddr(request);
56 | // if (DataUtil.isEmpty(ip)) {
57 | // logger.warn("==============>无法获取用户请求IP地址<===============");
58 | // bizResult.setReq(ReqResultCode.REQ_RESULT_CODE_ILLEGAL_IP_UNKNOW);
59 | // }
60 | // try {
61 | // if (!authorizeService.whiteIPCheck(request, ip)) {
62 | // logger.warn("非法请求,来源地址:" + ip + ";请求URI:" + request.getRequestURI());
63 | // bizResult.setReq(ReqResultCode.REQ_RESULT_CODE_ILLEGAL_IP);
64 | // } else {
65 | // try {
66 | // return (BizResult) joinPoint.proceed();
67 | // } catch (Throwable e) {
68 | // e.printStackTrace();
69 | // }
70 | // }
71 | // } catch (BusinessException e) {
72 | // e.printStackTrace();
73 | // }
74 | return null;
75 | }
76 |
77 | /**
78 | * getIpAddr: 防止添加代理的情况下,依旧过去获取真实IP地址
79 | *
80 | * @author guooo Date:2016年12月28日上午11:14:44
81 | * @param request
82 | * @return
83 | * @since JDK 1.6
84 | */
85 | public String getIpAddr(HttpServletRequest request) {
86 | String ip = request.getHeader("x-forwarded-for");
87 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
88 | ip = request.getHeader("Proxy-Client-IP");
89 | }
90 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
91 | ip = request.getHeader("WL-Proxy-Client-IP");
92 | }
93 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
94 | ip = request.getRemoteAddr();
95 | }
96 | //多级反向代理的话,X-Forwarded-For的值并不止一个
97 | if (ip.split(",").length > 1) {
98 | ip = ip.split(",")[0];
99 | }
100 | return ip;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/com/growithus/demo/config/MyExceptionHandler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Project Name:web-api-demo
3 | * File Name:ExceptionHandler.java
4 | * Package Name:com.growithus.demo.config
5 | * Date:2018年12月19日下午9:41:29
6 | * Copyright (c) 2018, 杭州知时信息科技有限公司 All Rights Reserved.
7 | *
8 | */
9 |
10 | package com.growithus.demo.config;
11 |
12 | import org.apache.log4j.Logger;
13 | import org.springframework.web.bind.annotation.ExceptionHandler;
14 | import org.springframework.web.bind.annotation.RestControllerAdvice;
15 |
16 | import com.alibaba.fastjson.JSONObject;
17 |
18 | /**
19 | * ClassName:ExceptionHandler
20 | * Function:
21 | * Date: 2018年12月19日 下午9:41:29
22 | * @author apple
23 | * @version
24 | * @since JDK 1.6
25 | * @see
26 | */
27 | @RestControllerAdvice
28 | public class MyExceptionHandler {
29 |
30 |
31 | Logger logger = Logger.getLogger(getClass());
32 |
33 | @ExceptionHandler(Exception.class)
34 | public String handleException(Exception e) {
35 | JSONObject jsonObject = new JSONObject();
36 | jsonObject.put("code", 1);
37 | jsonObject.put("errMsg", e.getMessage());
38 | return jsonObject.toJSONString();
39 | }
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/src/main/java/com/growithus/demo/config/Swagger2Config.java:
--------------------------------------------------------------------------------
1 | package com.growithus.demo.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import springfox.documentation.builders.ApiInfoBuilder;
6 | import springfox.documentation.builders.PathSelectors;
7 | import springfox.documentation.builders.RequestHandlerSelectors;
8 | import springfox.documentation.service.ApiInfo;
9 | import springfox.documentation.service.Contact;
10 | import springfox.documentation.spi.DocumentationType;
11 | import springfox.documentation.spring.web.plugins.Docket;
12 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
13 |
14 | /**
15 | * API服务
16 | *
17 | * @author guooo 公众号:growithus 2018年10月25日 下午1:43:40
18 | *
19 | */
20 | @EnableSwagger2
21 | @Configuration
22 | public class Swagger2Config {
23 |
24 | @Bean
25 | public Docket createRestApi() {
26 | return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
27 | // 为当前包路径
28 | .apis(RequestHandlerSelectors.any()).paths(PathSelectors.any()).build();
29 | }
30 |
31 | // 构建 api文档的详细信息函数
32 | private ApiInfo apiInfo() {
33 | return new ApiInfoBuilder()
34 | // 页面标题
35 | .title("C端App的API服务,基于SpringBoot2+Swagger2")
36 | // 创建人
37 | .contact(new Contact("guooo", "个人公众号:growithus,主页:https://backkoms.github.io/", "x@x.com"))
38 | // 版本号
39 | .version("1.0")
40 | // 描述
41 | .description("swagger描述的api文档").build();
42 | }
43 | }
--------------------------------------------------------------------------------
/src/main/java/com/growithus/demo/controller/APITestController.java:
--------------------------------------------------------------------------------
1 | package com.growithus.demo.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RequestMethod;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | import com.alibaba.dubbo.config.annotation.Reference;
8 | import com.growithus.service.demo.ifc.channel.DemoService;
9 |
10 | /**
11 | * test controller
12 | *
13 | * @author guooo 公众号:growithus 2018年10月25日 下午1:49:57
14 | *
15 | */
16 | @RestController
17 | public class APITestController {
18 |
19 | @Reference(version = "${service.version}", mock = "true",async = true)
20 | private DemoService demoService;
21 |
22 | /**
23 | * 调用后端dubbo服务
24 | *
25 | * @param input
26 | * @return
27 | */
28 | @RequestMapping(value = "rand", method = RequestMethod.POST)
29 | public String get(String input) {
30 | return demoService.hello("demo");
31 | }
32 |
33 | /**
34 | * 简单测试案例
35 | *
36 | * @param tid
37 | * @return
38 | */
39 | @RequestMapping(value = "getActDtl", method = RequestMethod.POST)
40 | public String getAccountDetail(String tid) {
41 | return "hello detail";
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | session-timeout: 1800
3 | debug: true
4 | spring:
5 | jackson:
6 | time-zone: GMT+8
7 | date-format: yyyy-MM-dd HH:mm:ss
8 |
9 | #dubbo config
10 | dubbo:
11 | registry:
12 | address: zookeeper://localhost:2181
--------------------------------------------------------------------------------
/src/main/resources/application-pro.yml:
--------------------------------------------------------------------------------
1 | server:
2 | session-timeout: 1800
3 | spring:
4 | jackson:
5 | time-zone: GMT+8
6 | date-format: yyyy-MM-dd HH:mm:ss
7 | #dubbo config
8 | dubbo:
9 | registry:
10 | address: zookeeper://localhost:2181
--------------------------------------------------------------------------------
/src/main/resources/application-test.yml:
--------------------------------------------------------------------------------
1 | server:
2 | session-timeout: 1800
3 | debug: true
4 | spring:
5 | jackson:
6 | time-zone: GMT+8
7 | date-format: yyyy-MM-dd HH:mm:ss
8 | #dubbo config
9 | dubbo:
10 | registry:
11 | address: zookeeper://localhost:2181
--------------------------------------------------------------------------------
/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | session-timeout: 1800
3 | port: 8082
4 |
5 | spring:
6 | profiles:
7 | active: dev
8 |
9 | #service version config
10 | service:
11 | version: 1.0.0
12 |
13 | #dubbo config
14 | dubbo:
15 | application:
16 | id: web-api-demo
17 | name: web-api-demo
18 | protocol:
19 | id: dubbo
20 | name: dubbo
21 | port: 20881
22 | consumer:
23 | check: false
24 | timeout: 2000
--------------------------------------------------------------------------------
/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | # LOG4J\u914D\u7F6E
2 | log4j.rootCategory=DEBUG, stdout,ServerDailyRollingFile
3 | # \u63A7\u5236\u53F0\u8F93\u51FA
4 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
5 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
6 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n
7 |
8 |
9 | log4j.appender.ServerDailyRollingFile=org.apache.log4j.DailyRollingFileAppender
10 | log4j.appender.ServerDailyRollingFile.DatePattern='.'yyyy-MM-dd
11 | log4j.appender.ServerDailyRollingFile.File=/tmp/log/web-api-demo.log
12 | log4j.appender.ServerDailyRollingFile.layout=org.apache.log4j.PatternLayout
13 | log4j.appender.ServerDailyRollingFile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p [%c] - %m%n
14 | log4j.appender.ServerDailyRollingFile.Append=true
--------------------------------------------------------------------------------
/src/test/java/com/growithus/demo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.growithus.demo;
2 |
3 |
4 | import org.apache.log4j.Logger;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.boot.test.context.SpringBootTest;
8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9 |
10 |
11 | @RunWith(SpringJUnit4ClassRunner.class)
12 | @SpringBootTest
13 | public class ApplicationTest {
14 |
15 | private Logger logger = Logger.getLogger(getClass());
16 |
17 | @Test
18 | public void test() throws Exception {
19 | logger.info("输出info");
20 | logger.debug("输出debug");
21 | logger.error("输出error");
22 | }
23 |
24 | }
--------------------------------------------------------------------------------