fix:工具类

上级 5de68e8a
......@@ -2,6 +2,18 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<parent>
<groupId>com.kwan.springcloudalibaba</groupId>
<artifactId>nacos-server-parent</artifactId>
......@@ -32,16 +44,28 @@
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-openfeign</artifactId>-->
<!-- <version>2.0.0.RELEASE</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-hystrix</artifactId>-->
<!-- <version>1.4.7.RELEASE</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.21</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.kwan.springcloudalibaba.util;
import cn.hutool.core.date.StopWatch;
import com.alibaba.fastjson2.JSON;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.StopWatch;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* 字符串是否存在文件中
......@@ -41,7 +41,7 @@ public class FileContains {
final List<String> isNotExist = new ArrayList<>();
//获取picPath下面所有的文件名
final List<String> picNames = getPicName(PIC_PATH);
log.info("图片总数为{}", picNames.size());
System.out.println("图片总数为" + picNames.size());
for (String word : picNames) {
IS_EXIST = false;
//指定类型的文件
......@@ -54,10 +54,10 @@ public class FileContains {
deletePic(PIC_PATH + word);
}
}
log.info("不存在图片总数为{}", isNotExist.size());
System.out.println("不存在图片总数为" + isNotExist.size());
stopWatch.stop();
//毫秒输出
log.info(String.valueOf(stopWatch.getTime(TimeUnit.MILLISECONDS)));
System.out.println(JSON.toJSONString(stopWatch.getTaskInfo()));
}
/**
......
......@@ -2,17 +2,14 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.kwan.springcloudalibaba</groupId>
<artifactId>nacos-server-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>nacos-server-consumer</artifactId>
<name>nacos-server-consumer</name>
<description>nacos-server-consumer</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......@@ -20,7 +17,6 @@
<spring-boot.version>2.3.7.RELEASE</spring-boot.version>
<spring-cloud-alibaba.version>2.2.2.RELEASE</spring-cloud-alibaba.version>
</properties>
<dependencies>
<dependency>
<groupId>com.kwan.springcloudalibaba</groupId>
......@@ -31,7 +27,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
......@@ -49,10 +44,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
......@@ -63,8 +54,5 @@
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
</dependencies>
</project>
</project>
\ No newline at end of file
......@@ -23,7 +23,7 @@ public class ConsumerUserController {
@Autowired
private RestTemplate restTemplate;
@Autowired
private FeignUserService computeClient;
private FeignUserService feignUserService;
@Autowired
private DiscoveryClient discoveryClient;
......@@ -85,7 +85,7 @@ public class ConsumerUserController {
*/
@GetMapping(value = "/{id}", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE)
public Result getUserById(@PathVariable Integer id) {
return Result.ok(computeClient.selectOne(id));
return Result.ok(feignUserService.selectOne(id));
}
......
......@@ -16,8 +16,8 @@
<dependencies>
<dependency>
<groupId>com.kwan.springcloudalibaba</groupId>
<artifactId>nacos-server-common</artifactId>
<version>1.0.0</version>
<artifactId>nacos-server-feign-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
......@@ -67,6 +67,18 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.kwan.springcloudalibaba;
import com.alibaba.cloud.nacos.ribbon.NacosRule;
import com.netflix.loadbalancer.IPing;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.PingUrl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
/**
......@@ -11,9 +18,25 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @version : 2.2.0
* @date : 2023/1/17 12:37
*/
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class SentinelConsumerApplication {
@Bean
public IRule randomRule() {
return new NacosRule(); //nacos的策略
// return new RandomRule(); //随机
//return new RoundRobinRule(); //轮训
//return new BestAvailableRule();
//return new ZoneAvoidanceRule(); //新版本默认的策略
}
@Bean
public IPing iping() {
return new PingUrl();
}
public static void main(String[] args) {
SpringApplication.run(SentinelConsumerApplication.class, args);
}
......
......@@ -3,8 +3,10 @@ package com.kwan.springcloudalibaba.controller;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.kwan.springcloudalibaba.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -19,6 +21,24 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/sentinel")
public class SentinelController {
@Autowired
private FeignUserService feignUserService;
/**
* feign调用
* http://127.0.0.1:8085/nacos/consumer/1
* <p>
* http://localhost:9091/user/1
*
* @param id
* @return
*/
@GetMapping(value = "/{id}", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE)
public Result getUserById(@PathVariable Integer id) {
return Result.ok(feignUserService.selectOne(id));
}
/**
* 获取配置的变量
* http://localhost:8086/sentinel/nameInfo
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册