springcloud 学习笔记

---恢复内容开始---

1. pom配置

    1.1 引入spring boot 依赖

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELAEASE</version>
    </parent>
POM配置

 

    1.2引入springcloud依赖

    1.3添加springboot的依赖

  1 <?xml version="1.0" encoding="UTF-8"?>
  2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4     <modelVersion>4.0.0</modelVersion>
  5 
  6     <artifactId>iop-claim-service</artifactId>
  7 
  8     <name>iop-claim-service</name>
  9 
 10     <parent>
 11         <groupId>com.sinosoft</groupId>
 12         <artifactId>BoCommlife-iop</artifactId>
 13         <version>0.0.1</version>
 14     </parent>
 15 
 16     <dependencies>
 17         <dependency>  
 18             <groupId>com.alibaba</groupId>  
 19             <artifactId>fastjson</artifactId>  
 20             <version>1.2.4</version>  
 21         </dependency>
 22         <dependency>
 23             <groupId>org.springframework.boot</groupId>
 24             <artifactId>spring-boot-starter-undertow</artifactId>
 25         </dependency>
 26         <dependency>
 27             <groupId>org.springframework.boot</groupId>
 28             <artifactId>spring-boot-starter-test</artifactId>
 29             <scope>test</scope>
 30         </dependency>
 31         <dependency>
 32             <groupId>org.springframework.boot</groupId>
 33             <artifactId>spring-boot-starter-web</artifactId>
 34         </dependency>
 35         <dependency>
 36             <groupId>org.springframework.cloud</groupId>
 37             <artifactId>spring-cloud-starter-eureka</artifactId>
 38         </dependency>
 39         <!-- 整合ribbon -->
 40         <dependency>
 41             <groupId>org.springframework.cloud</groupId>
 42             <artifactId>spring-cloud-starter-feign</artifactId>
 43         </dependency>
 44         <dependency>
 45             <groupId>org.springframework.boot</groupId>
 46             <artifactId>spring-boot-starter-actuator</artifactId>
 47         </dependency>
 48         <dependency>
 49             <groupId>org.mybatis.spring.boot</groupId>
 50             <artifactId>mybatis-spring-boot-starter</artifactId>
 51             <version>1.1.1</version>
 52         </dependency>
 53         <dependency>
 54             <groupId>com.zaxxer</groupId>
 55             <artifactId>HikariCP</artifactId>
 56             <!-- 版本号可以不用指定,Spring Boot会选用合适的版本 -->
 57         </dependency>
 58         <!-- log4j. -->
 59 <!--         <dependency> -->
 60 <!--             <groupId>org.apache.logging.log4j</groupId> -->
 61 <!--             <artifactId>log4j</artifactId> -->
 62 <!--             <version>2.6.2</version> -->
 63 <!--             <type>pom</type> -->
 64 <!--         </dependency> -->
 65         <dependency>
 66             <groupId>org.mybatis.generator</groupId>
 67             <artifactId>mybatis-generator-core</artifactId>
 68             <version>1.3.2</version>
 69         </dependency>
 70         <dependency>
 71             <groupId>mysql</groupId>
 72             <artifactId>mysql-connector-java</artifactId>
 73             <scope>runtime</scope>
 74         </dependency>
 75         <dependency>
 76             <groupId>io.jsonwebtoken</groupId>
 77             <artifactId>jjwt</artifactId>
 78             <version>0.6.0</version>
 79         </dependency>
 80         <dependency>
 81             <groupId>io.springfox</groupId>
 82             <artifactId>springfox-swagger-ui</artifactId>
 83             <version>2.5.0</version>
 84             <scope>compile</scope>
 85         </dependency>
 86         <dependency>
 87             <groupId>io.springfox</groupId>
 88             <artifactId>springfox-swagger2</artifactId>
 89             <version>2.5.0</version>
 90             <scope>compile</scope>
 91         </dependency>
 92         <dependency>
 93             <groupId>io.springfox</groupId>
 94             <artifactId>springfox-swagger-ui</artifactId>
 95             <version>2.5.0</version>
 96         </dependency>
 97         <dependency>
 98             <groupId>org.springframework.cloud</groupId>
 99             <artifactId>spring-cloud-config-client</artifactId>
100         </dependency>
101         <dependency>
102             <groupId>org.springframework.cloud</groupId>
103             <artifactId>spring-cloud-starter-hystrix</artifactId>
104         </dependency>
105         <dependency>
106             <groupId>org.springframework.cloud</groupId>
107             <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
108         </dependency>
109         <dependency>
110             <groupId>org.springframework.cloud</groupId>
111             <artifactId>spring-cloud-starter-bus-amqp</artifactId>
112         </dependency>
113         <dependency>
114             <groupId>org.springframework.boot</groupId>
115             <artifactId>spring-boot-starter-data-redis</artifactId>
116         </dependency>
117         <dependency>
118             <groupId>org.springframework.boot</groupId>
119             <artifactId>spring-boot-starter-hateoas</artifactId>
120         </dependency>
121         <dependency>
122             <groupId>org.springframework.boot</groupId>
123             <artifactId>spring-boot-actuator-docs</artifactId>
124         </dependency>
125         <dependency>
126             <groupId>org.webjars</groupId>
127             <artifactId>hal-browser</artifactId>
128         </dependency>
129         <dependency>
130             <groupId>com.alibaba</groupId>
131             <artifactId>druid</artifactId>
132             <version>1.0.20</version>
133         </dependency>
134         <dependency>
135             <groupId>com.github.pagehelper</groupId>
136             <artifactId>pagehelper</artifactId>
137             <version>4.1.6</version>
138         </dependency>
139         <dependency>
140             <groupId>com.sinosoft</groupId>
141             <artifactId>iop-common</artifactId>
142             <version>0.0.1</version>
143         </dependency>
144                 <dependency>
145             <groupId>com.sunecm</groupId>
146             <artifactId>sunecm-client</artifactId>
147             <version>0.0.1</version>
148         </dependency>
149         <dependency>
150             <groupId>com.sunecm</groupId>
151             <artifactId>socketTransClient</artifactId>
152             <version>1.4</version>
153         </dependency>
154     </dependencies>
155     <build>
156         <plugins>
157             <plugin>
158                 <groupId>org.springframework.boot</groupId>
159                 <artifactId>spring-boot-maven-plugin</artifactId>
160             </plugin>
161         </plugins>
162     </build>
163 </project>
pom

 

其中spring-boot-starter-web提供了spring mvc的支持

2.创建controller

    /**
     * 
     * 赔案进度查询
     * @param requestData
     * @return
     */
    @ApiOperation(value = "赔案进度查询", notes = "赔案进度查询接口")
    @RequestMapping(value = "/claimProcess", method = RequestMethod.POST)
    public String claimProcessQry(@RequestBody String requestData) {
        Long startTime = System.currentTimeMillis();
        String responseData = "";
        try {
            log.info("[claimProcessQry-赔案进度查询-请求报文]" + requestData);
            // 文件解密
            requestData = AESPlus.decrypt(requestData);
            // 校验重复交易
            if (!commonDao.isOK(requestData)) {
                responseData = CommonUtil.reResponseData(requestData, "02", "重复交易");
                return responseData;
            }
            responseData = claimProcessService.claimProcessQry(requestData);
            return responseData;
        } catch (Exception e) {
            // 异常捕捉
            responseData = CommonUtil.reResponseData(requestData, "03", e.getMessage());
            return responseData;
        } finally {
            // 存放前端日志
            log.info("[claimProcessQry-赔案进度查询-返回报文]" + responseData);
            commonDao.saveClientLog(startTime, requestData, responseData);
        }
    }
controller

 

---恢复内容结束---

1. pom配置

    1.1 引入spring boot 依赖

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELAEASE</version>
    </parent>
POM配置

 

    1.2引入springcloud依赖

    1.3添加springboot的依赖

  1 <?xml version="1.0" encoding="UTF-8"?>
  2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4     <modelVersion>4.0.0</modelVersion>
  5 
  6     <artifactId>iop-claim-service</artifactId>
  7 
  8     <name>iop-claim-service</name>
  9 
 10     <parent>
 11         <groupId>com.sinosoft</groupId>
 12         <artifactId>BoCommlife-iop</artifactId>
 13         <version>0.0.1</version>
 14     </parent>
 15 
 16     <dependencies>
 17         <dependency>  
 18             <groupId>com.alibaba</groupId>  
 19             <artifactId>fastjson</artifactId>  
 20             <version>1.2.4</version>  
 21         </dependency>
 22         <dependency>
 23             <groupId>org.springframework.boot</groupId>
 24             <artifactId>spring-boot-starter-undertow</artifactId>
 25         </dependency>
 26         <dependency>
 27             <groupId>org.springframework.boot</groupId>
 28             <artifactId>spring-boot-starter-test</artifactId>
 29             <scope>test</scope>
 30         </dependency>
 31         <dependency>
 32             <groupId>org.springframework.boot</groupId>
 33             <artifactId>spring-boot-starter-web</artifactId>
 34         </dependency>
 35         <dependency>
 36             <groupId>org.springframework.cloud</groupId>
 37             <artifactId>spring-cloud-starter-eureka</artifactId>
 38         </dependency>
 39         <!-- 整合ribbon -->
 40         <dependency>
 41             <groupId>org.springframework.cloud</groupId>
 42             <artifactId>spring-cloud-starter-feign</artifactId>
 43         </dependency>
 44         <dependency>
 45             <groupId>org.springframework.boot</groupId>
 46             <artifactId>spring-boot-starter-actuator</artifactId>
 47         </dependency>
 48         <dependency>
 49             <groupId>org.mybatis.spring.boot</groupId>
 50             <artifactId>mybatis-spring-boot-starter</artifactId>
 51             <version>1.1.1</version>
 52         </dependency>
 53         <dependency>
 54             <groupId>com.zaxxer</groupId>
 55             <artifactId>HikariCP</artifactId>
 56             <!-- 版本号可以不用指定,Spring Boot会选用合适的版本 -->
 57         </dependency>
 58         <!-- log4j. -->
 59 <!--         <dependency> -->
 60 <!--             <groupId>org.apache.logging.log4j</groupId> -->
 61 <!--             <artifactId>log4j</artifactId> -->
 62 <!--             <version>2.6.2</version> -->
 63 <!--             <type>pom</type> -->
 64 <!--         </dependency> -->
 65         <dependency>
 66             <groupId>org.mybatis.generator</groupId>
 67             <artifactId>mybatis-generator-core</artifactId>
 68             <version>1.3.2</version>
 69         </dependency>
 70         <dependency>
 71             <groupId>mysql</groupId>
 72             <artifactId>mysql-connector-java</artifactId>
 73             <scope>runtime</scope>
 74         </dependency>
 75         <dependency>
 76             <groupId>io.jsonwebtoken</groupId>
 77             <artifactId>jjwt</artifactId>
 78             <version>0.6.0</version>
 79         </dependency>
 80         <dependency>
 81             <groupId>io.springfox</groupId>
 82             <artifactId>springfox-swagger-ui</artifactId>
 83             <version>2.5.0</version>
 84             <scope>compile</scope>
 85         </dependency>
 86         <dependency>
 87             <groupId>io.springfox</groupId>
 88             <artifactId>springfox-swagger2</artifactId>
 89             <version>2.5.0</version>
 90             <scope>compile</scope>
 91         </dependency>
 92         <dependency>
 93             <groupId>io.springfox</groupId>
 94             <artifactId>springfox-swagger-ui</artifactId>
 95             <version>2.5.0</version>
 96         </dependency>
 97         <dependency>
 98             <groupId>org.springframework.cloud</groupId>
 99             <artifactId>spring-cloud-config-client</artifactId>
100         </dependency>
101         <dependency>
102             <groupId>org.springframework.cloud</groupId>
103             <artifactId>spring-cloud-starter-hystrix</artifactId>
104         </dependency>
105         <dependency>
106             <groupId>org.springframework.cloud</groupId>
107             <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
108         </dependency>
109         <dependency>
110             <groupId>org.springframework.cloud</groupId>
111             <artifactId>spring-cloud-starter-bus-amqp</artifactId>
112         </dependency>
113         <dependency>
114             <groupId>org.springframework.boot</groupId>
115             <artifactId>spring-boot-starter-data-redis</artifactId>
116         </dependency>
117         <dependency>
118             <groupId>org.springframework.boot</groupId>
119             <artifactId>spring-boot-starter-hateoas</artifactId>
120         </dependency>
121         <dependency>
122             <groupId>org.springframework.boot</groupId>
123             <artifactId>spring-boot-actuator-docs</artifactId>
124         </dependency>
125         <dependency>
126             <groupId>org.webjars</groupId>
127             <artifactId>hal-browser</artifactId>
128         </dependency>
129         <dependency>
130             <groupId>com.alibaba</groupId>
131             <artifactId>druid</artifactId>
132             <version>1.0.20</version>
133         </dependency>
134         <dependency>
135             <groupId>com.github.pagehelper</groupId>
136             <artifactId>pagehelper</artifactId>
137             <version>4.1.6</version>
138         </dependency>
139         <dependency>
140             <groupId>com.sinosoft</groupId>
141             <artifactId>iop-common</artifactId>
142             <version>0.0.1</version>
143         </dependency>
144                 <dependency>
145             <groupId>com.sunecm</groupId>
146             <artifactId>sunecm-client</artifactId>
147             <version>0.0.1</version>
148         </dependency>
149         <dependency>
150             <groupId>com.sunecm</groupId>
151             <artifactId>socketTransClient</artifactId>
152             <version>1.4</version>
153         </dependency>
154     </dependencies>
155     <build>
156         <plugins>
157             <plugin>
158                 <groupId>org.springframework.boot</groupId>
159                 <artifactId>spring-boot-maven-plugin</artifactId>
160             </plugin>
161         </plugins>
162     </build>
163 </project>
pom

 

其中spring-boot-starter-web提供了spring mvc的支持

2.创建controller

    /**
     * 
     * 赔案进度查询
     * @param requestData
     * @return
     */
    @ApiOperation(value = "赔案进度查询", notes = "赔案进度查询接口")
    @RequestMapping(value = "/claimProcess", method = RequestMethod.POST)
    public String claimProcessQry(@RequestBody String requestData) {
        Long startTime = System.currentTimeMillis();
        String responseData = "";
        try {
            log.info("[claimProcessQry-赔案进度查询-请求报文]" + requestData);
            // 文件解密
            requestData = AESPlus.decrypt(requestData);
            // 校验重复交易
            if (!commonDao.isOK(requestData)) {
                responseData = CommonUtil.reResponseData(requestData, "02", "重复交易");
                return responseData;
            }
            responseData = claimProcessService.claimProcessQry(requestData);
            return responseData;
        } catch (Exception e) {
            // 异常捕捉
            responseData = CommonUtil.reResponseData(requestData, "03", e.getMessage());
            return responseData;
        } finally {
            // 存放前端日志
            log.info("[claimProcessQry-赔案进度查询-返回报文]" + responseData);
            commonDao.saveClientLog(startTime, requestData, responseData);
        }
    }
controller

 

posted @ 2017-08-14 10:20  染颜  阅读(693)  评论(0编辑  收藏  举报