Commit f5179c08 by 李根

写的是个锤子

parent 44c47fc1
...@@ -16,15 +16,11 @@ ...@@ -16,15 +16,11 @@
</properties> </properties>
<dependencies> <dependencies>
<!-- <dependency>-->
<!-- <groupId>com.alibaba.csp</groupId>-->
<!-- <artifactId>sentinel-core</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>--> <dependency>
<!-- <groupId>com.alibaba.csp</groupId>--> <groupId>com.alibaba.csp</groupId>
<!-- <artifactId>sentinel-annotation-aspectj</artifactId>--> <artifactId>sentinel-core</artifactId>
<!-- </dependency>--> </dependency>
<dependency> <dependency>
<groupId>com.alibaba.csp</groupId> <groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-transport-simple-http</artifactId> <artifactId>sentinel-transport-simple-http</artifactId>
...@@ -34,26 +30,10 @@ ...@@ -34,26 +30,10 @@
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<version>2.1.0.RELEASE</version> <version>2.1.0.RELEASE</version>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-extension</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.alibaba.csp</groupId> <groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId> <artifactId>sentinel-datasource-nacos</artifactId>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>com.alibaba.csp</groupId>-->
<!-- <artifactId>sentinel-extension</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-aop</artifactId>-->
<!-- <version>${spring.boot.version}</version>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
......
...@@ -30,5 +30,4 @@ public class AopConfiguration { ...@@ -30,5 +30,4 @@ public class AopConfiguration {
// return new SentinelResourceAspect(); // return new SentinelResourceAspect();
// } // }
} }
...@@ -15,8 +15,9 @@ public class ApplicationRunnerImpl implements ApplicationRunner { ...@@ -15,8 +15,9 @@ public class ApplicationRunnerImpl implements ApplicationRunner {
@Autowired @Autowired
private NacosStartService nacosStartService; private NacosStartService nacosStartService;
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
nacosStartService.initNacosConfigFromNacos(); // nacosStartService.initNacosConfigFromNacos();
} }
} }
\ No newline at end of file
...@@ -13,7 +13,7 @@ import com.alibaba.fastjson.JSON; ...@@ -13,7 +13,7 @@ import com.alibaba.fastjson.JSON;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.context.annotation.Configuration;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
...@@ -26,12 +26,11 @@ import java.util.Properties; ...@@ -26,12 +26,11 @@ import java.util.Properties;
* @description: * @description:
* @date 2020/4/214:08 * @date 2020/4/214:08
*/ */
@Service @Configuration
public class NacosStartService { public class NacosStartService {
Logger logger = LoggerFactory.getLogger(this.getClass()); Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired @Autowired
private SentinelProperties sentinelProperties; private SentinelProperties sentinelProperties;
......
...@@ -15,12 +15,10 @@ ...@@ -15,12 +15,10 @@
*/ */
package com.alibaba.csp.sentinel.demo.springboot.nacos.controller; package com.alibaba.csp.sentinel.demo.springboot.nacos.controller;
import com.alibaba.cloud.sentinel.SentinelProperties;
import com.alibaba.csp.sentinel.annotation.SentinelResource; import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.StringUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
...@@ -35,10 +33,6 @@ public class DemoController { ...@@ -35,10 +33,6 @@ public class DemoController {
Logger logger = LoggerFactory.getLogger(DemoController.class); Logger logger = LoggerFactory.getLogger(DemoController.class);
@Autowired
private SentinelProperties sentinelProperties;
@Order(1) @Order(1)
@SentinelResource(value = "test1", blockHandler = "myBlockHandler", fallbackClass = FallBack.class, fallback = "test1FallBack") @SentinelResource(value = "test1", blockHandler = "myBlockHandler", fallbackClass = FallBack.class, fallback = "test1FallBack")
@GetMapping("/test1") @GetMapping("/test1")
......
...@@ -12,8 +12,12 @@ import org.springframework.stereotype.Component; ...@@ -12,8 +12,12 @@ import org.springframework.stereotype.Component;
@Component @Component
public class DemoNacosInitFunc implements InitFunc { public class DemoNacosInitFunc implements InitFunc {
/*
* 因为sentinel是SPI拓展接口不能使用,spring的ioc,所以下面的注入会报NPE。。。。
* */
@Autowired @Autowired
private NacosStartService nacosStartService; NacosStartService nacosStartService;
@Override @Override
public void init() throws Exception { public void init() throws Exception {
......
com.alibaba.csp.sentinel.demo.springboot.nacos.inti.DemoNacosInitFunc
\ No newline at end of file
spring.application.name=springboot-nacos spring.application.name=springboot-nacos
server.port=19966 server.port=19966
spring.cloud.sentinel.transport.dashboard=127.0.0.1:8080 spring.cloud.sentinel.transport.dashboard=127.0.0.1:8080
# ʽ1
spring.cloud.sentinel.datasource.ds3.nacos.server-addr=10.16.10.139:8848 spring.cloud.sentinel.datasource.ds3.nacos.server-addr=10.16.10.139:8848
spring.cloud.sentinel.datasource.ds3.nacos.dataId=springboot-nacos-flow-rules spring.cloud.sentinel.datasource.ds3.nacos.dataId=springboot-nacos-flow-rules
spring.cloud.sentinel.datasource.ds3.nacos.groupId=DEFAULT_GROUP spring.cloud.sentinel.datasource.ds3.nacos.groupId=DEFAULT_GROUP
......
com.alibaba.csp.sentinel.demo.springboot.nacos.init.DemoNacosInitFunc
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment