其他分享
首页 > 其他分享> > sentinel篇2-资源注解使用-结合SpringAOP

sentinel篇2-资源注解使用-结合SpringAOP

作者:互联网

前言

springboot应用集成sentinel

<dependency>
	<groupId>com.alibaba.csp</groupId>
	<artifactId>sentinel-core</artifactId>
	<version>${sentinel.version}</version>
</dependency>
<dependency>
	<groupId>com.alibaba.csp</groupId>
	<artifactId>sentinel-annotation-aspectj</artifactId>
	<version>${sentinel.version}</version>
</dependency>
<dependency>
	<groupId>com.alibaba.csp</groupId>
	<artifactId>sentinel-transport-simple-http</artifactId>
	<version>${sentinel.version}</version>
</dependency>

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>
@Configuration
public class SentinelAspectConfiguration {

    @Bean
    public SentinelResourceAspect sentinelResourceAspect() {
        return new SentinelResourceAspect();
    }
}
@Service
public class TestService {
	@SentinelResource(value = "resource1")
	public String resource1() {
		System.out.println("resource1");
		return "resource1";
	}
	
	public String notResource() {
		System.out.println("notResource");
		return "resource1";
	}
}

@RestController
public class Demo1Controller {
	@Autowired
    private TestService service;
	
	@GetMapping("/resource1")
    public String resource1() {
		
        return service.resource1() + " " + LocalDateTime.now().toString();
    }
	
	@GetMapping("/notResource")
    public String notResource() {
		
        return service.notResource() + " " + LocalDateTime.now().toString();
    }
}

有效参考

标签:return,String,class,sentinel,SpringAOP,注解,resource1,public
来源: https://www.cnblogs.com/noodlerkun/p/15541115.html