Update java.md

This commit is contained in:
caishi 2025-01-24 10:21:40 +08:00
parent b149d9dfcc
commit 494827474e
1 changed files with 8 additions and 14 deletions

22
java.md
View File

@ -1,26 +1,20 @@
// Refer to document: https://github.com/nacos-group/nacos-examples/tree/master/nacos-spring-boot-example/nacos-spring-boot-config-example // Refer to document: https://github.com/nacos-group/nacos-examples/tree/master/nacos-spring-cloud-example/nacos-spring-cloud-config-example
package com.alibaba.nacos.example.spring.boot.controller; package com.alibaba.nacos.example.spring.cloud.controller;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller; import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController;
import static org.springframework.web.bind.annotation.RequestMethod.GET; @RestController
@RequestMapping("/config")
@Controller @RefreshScope
@RequestMapping("config")
public class ConfigController { public class ConfigController {
@Value("${useLocalCache:false}") @Value("${useLocalCache:false}")
private boolean useLocalCache; private boolean useLocalCache;
public void setUseLocalCache(boolean useLocalCache) { @RequestMapping("/get")
this.useLocalCache = useLocalCache;
}
@RequestMapping(value = "/get", method = GET)
@ResponseBody
public boolean get() { public boolean get() {
return useLocalCache; return useLocalCache;
} }