10 |
错误Path!
11 |

12 |
There seems to be a problem with the page you requested
13 | ().
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/ErrorPageDemoSvc/ErrorPageSvc_README.md:
--------------------------------------------------------------------------------
1 | # ErrorPageDemoSvc
2 |
3 | http://127.0.0.1:5501/
4 | http://localhost:5501/swagger-ui.html#/
5 |
6 | 删除swagger的SwaggerConfig,静态资源,就是图片和css文件能正常加载了
7 |
8 |
--------------------------------------------------------------------------------
/ErrorPageDemoSvc/src/main/java/com/yq/ErrorPageApplication.java:
--------------------------------------------------------------------------------
1 | package com.yq;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class ErrorPageApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(ErrorPageApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/ErrorPageDemoSvc/src/main/java/com/yq/domain/User.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | package com.yq.domain;
4 |
5 | import lombok.Data;
6 |
7 | import java.util.Date;
8 |
9 | /**
10 | * Simple to Introduction
11 | * className: User
12 | *
13 | * @author EricYang
14 | * @version 2018/6/29 23:43
15 | */
16 | @Data
17 | public class User {
18 | String id;
19 | String name;
20 | String mail;
21 | Date regDate;
22 | }
23 |
--------------------------------------------------------------------------------
/ErrorPageDemoSvc/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 | server.port=5501
3 |
4 | spring.application.name=error-service
5 |
6 | spring.mvc.static-path-pattern=/**
7 | spring.resources.chain.strategy.content.enabled=true
8 | spring.resources.chain.strategy.content.paths=/**
9 | spring.resources.static-locations=/static/css/,classpath:/static/images/,classpath:/static/js/,classpath:/static/
10 | #spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
11 |
12 | #security.user.password=none
13 | #security.basic.enabled=false
14 |
--------------------------------------------------------------------------------
/ErrorPageDemoSvc/src/main/resources/public/myErrorPage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ErrorPageDemoSvc/src/main/resources/public/myErrorPage.png
--------------------------------------------------------------------------------
/ErrorPageDemoSvc/src/main/resources/static/myErrorPage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ErrorPageDemoSvc/src/main/resources/static/myErrorPage.png
--------------------------------------------------------------------------------
/ErrorPageDemoSvc/src/main/resources/templates/error.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
12 |
错误Path!
13 |
![]()
14 |
There seems to be a problem with the page you requested
15 | ().
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/EurekaCommoditySvc/src/main/java/com/yq/EurekaUserApplication.java:
--------------------------------------------------------------------------------
1 | package com.yq;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
6 |
7 | @SpringBootApplication
8 | @EnableEurekaClient
9 |
10 |
11 | public class EurekaUserApplication {
12 |
13 | public static void main(String[] args) {
14 | SpringApplication.run(EurekaUserApplication.class, args);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/EurekaCommoditySvc/src/main/java/com/yq/domain/Commodity.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | package com.yq.domain;
4 |
5 | import lombok.Data;
6 |
7 | import java.util.Date;
8 |
9 | /**
10 | * Simple to Introduction
11 | * className: Commodity
12 | *
13 | * @author EricYang
14 | * @version 2018/6/30 0:13
15 | */
16 | @Data
17 | public class Commodity {
18 | String id;
19 | String name;
20 | String description;
21 | String price;
22 | String count;
23 | String picUrl;
24 | Date onlineDate;
25 | }
26 |
--------------------------------------------------------------------------------
/EurekaCommoditySvc/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 |
2 | eureka:
3 | client:
4 | serviceUrl:
5 | defaultZone: http://localhost:7700/eureka/
6 |
7 | server:
8 | port: 6602
9 |
10 | spring:
11 | application:
12 | name: commodity-service
13 |
14 | security:
15 | user:
16 | password: none
17 | basic:
18 | enabled: false
19 |
--------------------------------------------------------------------------------
/EurekaServerDemo/src/main/java/com/yq/EurekaServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.yq;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
7 |
8 | @EnableEurekaServer
9 | @SpringBootApplication
10 | public class EurekaServerApplication {
11 |
12 | public static void main(String[] args) {
13 | SpringApplication.run(EurekaServerApplication.class, args);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/EurekaServerDemo/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 7700
3 |
4 | eureka:
5 | instance:
6 | hostname: localhost
7 | client:
8 | registerWithEureka: false
9 | fetchRegistry: false
10 | serviceUrl:
11 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
--------------------------------------------------------------------------------
/EurekaUserSvc/UserSvc_README.md:
--------------------------------------------------------------------------------
1 | # EurekaUserSvc
2 |
3 | http://127.0.0.1:7700/
4 | http://localhost:6601/swagger-ui.html#/
5 |
6 |
--------------------------------------------------------------------------------
/EurekaUserSvc/src/main/java/com/yq/EurekaUserApplication.java:
--------------------------------------------------------------------------------
1 | package com.yq;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
6 |
7 | @SpringBootApplication
8 | @EnableEurekaClient
9 | public class EurekaUserApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(EurekaUserApplication.class, args);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/EurekaUserSvc/src/main/java/com/yq/domain/User.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | package com.yq.domain;
4 |
5 | import lombok.Data;
6 |
7 | import java.util.Date;
8 |
9 | /**
10 | * Simple to Introduction
11 | * className: User
12 | *
13 | * @author EricYang
14 | * @version 2018/6/29 23:43
15 | */
16 | @Data
17 | public class User {
18 | String id;
19 | String name;
20 | String mail;
21 | Date regDate;
22 | }
23 |
--------------------------------------------------------------------------------
/EurekaUserSvc/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/EurekaUserSvc/src/main/resources/application.properties
--------------------------------------------------------------------------------
/ExceptionDemo/README.md:
--------------------------------------------------------------------------------
1 | # SpringCloudTutorials
2 |
3 | http://127.0.0.1:8085/swagger-ui.html
4 |
5 | spring.mvc.throw-exception-if-no-handler-found=true
6 |
7 | @ExceptionHandler表示该方法可以处理的异常,可以多个,比如
8 | @ExceptionHandler({ NullPointerException.class, DataAccessException.class})
9 | 也可以针对不同的异常写不同的方法。@ExceptionHandler(Exception.class)可以处理所有的异常类型。
10 |
11 |
12 |
13 | AfterReturningAdvice
14 | ThrowsAdvice
15 | MethodInterceptor
16 |
17 | 事务 与 Afterthrowing 冲突, 通过order解决
--------------------------------------------------------------------------------
/ExceptionDemo/src/main/java/com/yq/exceptiondemo/ExecptionDemoApplication.java:
--------------------------------------------------------------------------------
1 | package com.yq.exceptiondemo;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 |
8 |
9 | @SpringBootApplication
10 | public class ExecptionDemoApplication {
11 | private static final Logger log = LoggerFactory.getLogger(ExecptionDemoApplication.class);
12 |
13 | public static void main(String[] args) {
14 |
15 | SpringApplication.run(ExecptionDemoApplication.class, args);
16 | log.info("Spring Boot start done!");
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/ExceptionDemo/src/main/java/com/yq/exceptiondemo/config/SystemLog.java:
--------------------------------------------------------------------------------
1 |
2 | package com.yq.exceptiondemo.config;
3 |
4 | import java.lang.annotation.Documented;
5 | import java.lang.annotation.ElementType;
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 | import java.lang.annotation.Target;
9 |
10 | /**
11 | * Simple to Introduction
12 | * className: SystemLog
13 | *
14 | * @author EricYang
15 | * @version 2018/6/9 18:38
16 | */
17 |
18 | @Target({ElementType.PARAMETER, ElementType.METHOD})
19 | @Retention(RetentionPolicy.RUNTIME)
20 | @Documented
21 | public @interface SystemLog {
22 | String description() default "";
23 | }
24 |
--------------------------------------------------------------------------------
/ExceptionDemo/src/main/java/com/yq/exceptiondemo/exception/BaseException.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | package com.yq.exceptiondemo.exception;
4 |
5 | import lombok.Data;
6 |
7 | @Data
8 | public class BaseException extends Throwable {
9 | private int code;
10 | private String myCause;
11 |
12 |
13 | public BaseException(int code, String myCause) {
14 | this.code = code;
15 | this.myCause = myCause;
16 |
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/ExceptionDemo/src/main/java/com/yq/exceptiondemo/exception/ComputerException.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | package com.yq.exceptiondemo.exception;
4 |
5 | import com.yq.exceptiondemo.utils.Constants;
6 | import lombok.Data;
7 |
8 | /**
9 | */
10 | @Data
11 | public class ComputerException extends BaseException {
12 |
13 | public ComputerException(String cause) {
14 | super(Constants.DIVIDE_ERROR, cause);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ExceptionDemo/src/main/java/com/yq/exceptiondemo/service/ComputerService.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | package com.yq.exceptiondemo.service;
4 |
5 | import com.yq.exceptiondemo.exception.ComputerException;
6 |
7 | /**
8 | * Simple to Introduction
9 | * className: ComputerService
10 |
11 | */
12 | public interface ComputerService {
13 | int divide(int a, int b);
14 |
15 | int divideCatchExecption(int a, int b) throws ComputerException;
16 | }
--------------------------------------------------------------------------------
/ExceptionDemo/src/main/java/com/yq/exceptiondemo/service/impl/ComputerServiceImpl.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | package com.yq.exceptiondemo.service.impl;
4 |
5 | import com.yq.exceptiondemo.exception.ComputerException;
6 | import com.yq.exceptiondemo.service.ComputerService;
7 | import com.yq.exceptiondemo.utils.Constants;
8 | import org.springframework.stereotype.Service;
9 |
10 | /**
11 | */
12 | @Service
13 | public class ComputerServiceImpl implements ComputerService {
14 |
15 | @Override
16 | public int divide(int a, int b) {
17 | int result = a / b;
18 | return result;
19 | }
20 |
21 | @Override
22 | public int divideCatchExecption(int a, int b) throws ComputerException {
23 | int result = 0;
24 | try {
25 | result = a / b;
26 | }
27 | catch (Exception ex) {
28 | throw new ComputerException(ex.getMessage() + ", a:" + a + ", b:" + b);
29 | }
30 |
31 | return result;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/ExceptionDemo/src/main/java/com/yq/exceptiondemo/utils/Constants.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | package com.yq.exceptiondemo.utils;
4 |
5 | /**
6 | * Simple to Introduction
7 | * className: Constants
8 | *
9 | * @author EricYang
10 | */
11 | public class Constants {
12 | public static final int QUERY_OK = 001;
13 | public static final int POST_OK = 002;
14 | public static final int DELETE_OK = 003;
15 | public static final int PUT_OK = 004;
16 |
17 | public static final int DIVIDE_ERROR = 005;
18 | public static final int PARAMETER_ERROR = 006;
19 | }
20 |
--------------------------------------------------------------------------------
/ExceptionDemo/src/main/java/com/yq/exceptiondemo/utils/ReturnResult.java:
--------------------------------------------------------------------------------
1 | package com.yq.exceptiondemo.utils;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import com.alibaba.fastjson.JSONObject;
5 | import lombok.Data;
6 |
7 | /**
8 | */
9 | @Data
10 | public class ReturnResult