mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
format code with maven plugins
This commit is contained in:
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.examples;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -6,6 +22,8 @@ import java.util.Properties;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosConfigManager;
|
||||
import com.alibaba.nacos.api.config.listener.Listener;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
@@ -17,17 +35,16 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosConfigProperties;
|
||||
import com.alibaba.nacos.api.config.listener.Listener;
|
||||
|
||||
/**
|
||||
* @author xiaojing, Jianwei Mao
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Component
|
||||
@@ -56,9 +73,8 @@ class SampleRunner implements ApplicationRunner {
|
||||
* For example, config data in Nacos is:
|
||||
*
|
||||
* user.name=Nacos user.age=25
|
||||
*
|
||||
* @param configInfo latest config data for specific dataId in Nacos
|
||||
* server
|
||||
* server
|
||||
*/
|
||||
@Override
|
||||
public void receiveConfigInfo(String configInfo) {
|
||||
@@ -78,6 +94,7 @@ class SampleRunner implements ApplicationRunner {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@RestController
|
||||
@@ -98,4 +115,5 @@ class SampleController {
|
||||
return "Hello Nacos Config!" + "Hello " + userName + " " + age + "!"
|
||||
+ nacosConfigManager.getConfigService();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,2 +1,2 @@
|
||||
server.port=18084
|
||||
management.endpoints.web.exposure.include=*
|
||||
management.endpoints.web.exposure.include=*
|
||||
|
@@ -1,4 +1,4 @@
|
||||
spring.application.name=nacos-config-example
|
||||
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
|
||||
spring.cloud.nacos.config.shared-data-ids=base-common.properties,common.properties
|
||||
spring.cloud.nacos.config.refreshable-dataids=common.properties
|
||||
spring.cloud.nacos.config.refreshable-dataids=common.properties
|
||||
|
@@ -1,5 +1,24 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.examples;
|
||||
|
||||
import com.alibaba.cloud.examples.ConsumerApplication.EchoService;
|
||||
import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
@@ -7,12 +26,11 @@ import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.alibaba.cloud.examples.ConsumerApplication.EchoService;
|
||||
import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
*/
|
||||
@@ -39,32 +57,38 @@ public class ConsumerApplication {
|
||||
SpringApplication.run(ConsumerApplication.class, args);
|
||||
}
|
||||
|
||||
@FeignClient(name = "service-provider", fallback = EchoServiceFallback.class, configuration = FeignConfiguration.class)
|
||||
@FeignClient(name = "service-provider", fallback = EchoServiceFallback.class,
|
||||
configuration = FeignConfiguration.class)
|
||||
public interface EchoService {
|
||||
@GetMapping(value = "/echo/{str}")
|
||||
|
||||
@GetMapping("/echo/{str}")
|
||||
String echo(@PathVariable("str") String str);
|
||||
|
||||
@GetMapping(value = "/divide")
|
||||
@GetMapping("/divide")
|
||||
String divide(@RequestParam("a") Integer a, @RequestParam("b") Integer b);
|
||||
|
||||
default String divide(Integer a) {
|
||||
return divide(a, 0);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/notFound")
|
||||
@GetMapping("/notFound")
|
||||
String notFound();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class FeignConfiguration {
|
||||
|
||||
@Bean
|
||||
public EchoServiceFallback echoServiceFallback() {
|
||||
return new EchoServiceFallback();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class EchoServiceFallback implements EchoService {
|
||||
|
||||
@Override
|
||||
public String echo(@PathVariable("str") String str) {
|
||||
return "echo fallback";
|
||||
@@ -79,4 +103,5 @@ class EchoServiceFallback implements EchoService {
|
||||
public String notFound() {
|
||||
return "notFound fallback";
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,12 +1,31 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.examples;
|
||||
|
||||
import com.alibaba.cloud.examples.ConsumerApplication.EchoService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.alibaba.cloud.examples.ConsumerApplication.EchoService;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
*/
|
||||
@@ -40,54 +59,55 @@ public class TestController {
|
||||
// });
|
||||
// }
|
||||
|
||||
@GetMapping(value = "/echo-rest/{str}")
|
||||
@GetMapping("/echo-rest/{str}")
|
||||
public String rest(@PathVariable String str) {
|
||||
return restTemplate.getForObject("http://service-provider/echo/" + str,
|
||||
String.class);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/index")
|
||||
@GetMapping("/index")
|
||||
public String index() {
|
||||
return restTemplate1.getForObject("http://service-provider", String.class);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/test")
|
||||
@GetMapping("/test")
|
||||
public String test() {
|
||||
return restTemplate1.getForObject("http://service-provider/test", String.class);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/sleep")
|
||||
@GetMapping("/sleep")
|
||||
public String sleep() {
|
||||
return restTemplate1.getForObject("http://service-provider/sleep", String.class);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/notFound-feign")
|
||||
@GetMapping("/notFound-feign")
|
||||
public String notFound() {
|
||||
return echoService.notFound();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/divide-feign")
|
||||
@GetMapping("/divide-feign")
|
||||
public String divide(@RequestParam Integer a, @RequestParam Integer b) {
|
||||
return echoService.divide(a, b);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/divide-feign2")
|
||||
@GetMapping("/divide-feign2")
|
||||
public String divide(@RequestParam Integer a) {
|
||||
return echoService.divide(a);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/echo-feign/{str}")
|
||||
@GetMapping("/echo-feign/{str}")
|
||||
public String feign(@PathVariable String str) {
|
||||
return echoService.echo(str);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/services/{service}")
|
||||
@GetMapping("/services/{service}")
|
||||
public Object client(@PathVariable String service) {
|
||||
return discoveryClient.getInstances(service);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/services")
|
||||
@GetMapping("/services")
|
||||
public Object services() {
|
||||
return discoveryClient.getServices();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,23 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.examples;
|
||||
|
||||
public class UrlCleaner {
|
||||
|
||||
public static String clean(String url) {
|
||||
System.out.println("enter urlCleaner");
|
||||
if (url.matches(".*/echo/.*")) {
|
||||
@@ -9,4 +26,5 @@ public class UrlCleaner {
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -14,4 +14,4 @@ spring.cloud.sentinel.datasource.ds1.file.rule-type=flow
|
||||
|
||||
spring.cloud.sentinel.datasource.ds2.file.file=classpath: degraderule.json
|
||||
spring.cloud.sentinel.datasource.ds2.file.data-type=json
|
||||
spring.cloud.sentinel.datasource.ds2.file.rule-type=degrade
|
||||
spring.cloud.sentinel.datasource.ds2.file.rule-type=degrade
|
||||
|
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.examples;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -5,7 +21,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
@@ -21,17 +40,17 @@ public class ProviderApplication {
|
||||
@RestController
|
||||
class EchoController {
|
||||
|
||||
@GetMapping(value = "/")
|
||||
@GetMapping("/")
|
||||
public ResponseEntity index() {
|
||||
return new ResponseEntity("index error", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/test")
|
||||
@GetMapping("/test")
|
||||
public ResponseEntity test() {
|
||||
return new ResponseEntity("error", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/sleep")
|
||||
@GetMapping("/sleep")
|
||||
public String sleep() {
|
||||
try {
|
||||
Thread.sleep(1000L);
|
||||
@@ -42,14 +61,16 @@ public class ProviderApplication {
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@GetMapping(value = "/echo/{string}")
|
||||
@GetMapping("/echo/{string}")
|
||||
public String echo(@PathVariable String string) {
|
||||
return "hello Nacos Discovery " + string;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/divide")
|
||||
@GetMapping("/divide")
|
||||
public String divide(@RequestParam Integer a, @RequestParam Integer b) {
|
||||
return String.valueOf(a / b);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
server.port=18082
|
||||
spring.application.name=service-provider
|
||||
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
|
||||
management.endpoints.web.exposure.include=*
|
||||
management.endpoints.web.exposure.include=*
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,8 +18,6 @@ package com.alibaba.cloud.examples;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@@ -28,7 +26,7 @@ public class GetConfigController {
|
||||
@Value("${config}")
|
||||
private String config;
|
||||
|
||||
@GetMapping(value = "/config")
|
||||
@GetMapping("/config")
|
||||
public String getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,4 +31,4 @@ public class SpringCloudConfigClientApplication {
|
||||
SpringApplication.run(SpringCloudConfigClientApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,4 +33,4 @@ public class SpringCloudConfigServerApplication {
|
||||
SpringApplication.run(SpringCloudConfigServerApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.examples;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
@@ -8,4 +8,4 @@ spring.cloud.gateway.routes[0].id=nacos-route
|
||||
spring.cloud.gateway.routes[0].uri=lb://service-gateway-provider
|
||||
spring.cloud.gateway.routes[0].predicates[0].name=Path
|
||||
spring.cloud.gateway.routes[0].predicates[0].args[pattern]=/nacos/**
|
||||
spring.cloud.gateway.routes[0].filters[0]=StripPrefix=1
|
||||
spring.cloud.gateway.routes[0].filters[0]=StripPrefix=1
|
||||
|
@@ -1,9 +1,28 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.examples;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
@@ -18,14 +37,17 @@ public class ProviderApplication {
|
||||
|
||||
@RestController
|
||||
class EchoController {
|
||||
@GetMapping(value = "/echo/{string}")
|
||||
|
||||
@GetMapping("/echo/{string}")
|
||||
public String echo(@PathVariable String string) {
|
||||
return "hello Nacos Discovery " + string;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/divide")
|
||||
@GetMapping("/divide")
|
||||
public String divide(@RequestParam Integer a, @RequestParam Integer b) {
|
||||
return String.valueOf(a / b);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
server.port=18086
|
||||
spring.application.name=service-gateway-provider
|
||||
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
|
||||
management.endpoints.web.exposure.include=*
|
||||
management.endpoints.web.exposure.include=*
|
||||
|
Reference in New Issue
Block a user