Java Spring Cloud - How to read a configuration in Nacos?

Viewed 146

I am going to read a configuration in Nacos in my controller. On Windows, I can read it correctly, but not on Linux. I need this to implement REST APIs for file uploading and downloading with Java Spring Cloud. I did get it on windows perfectly. But it doesn't work at all on Linux.

Here is the detail.

JDK: 1.8

pom.xml

<spring.boot.version>2.2.11.RELEASE</spring.boot.version>
<spring.plugin.version>2.2.0.RELEASE</spring.plugin.version>
<spring.cloud.version>Hoxton.SR8</spring.cloud.version>
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/media-file")
@Api(value = "File Upload", tags = "")
public class MediaFileController extends BladeController {
    public static final String MEDIA_FILE_TYPE_BOND_PRICE = "bondPrice";

    @Autowired
    public Environment env;

    @PostMapping("upload")
    @ApiOperationSupport(order = 12)
    @ApiOperation(value = "Upload", notes = "Import excel")
    public R upload(MultipartFile file, @ApiParam(value = "文件类型", required = true) @RequestParam 
    String type, @RequestParam Map<String, Object> data) {

        log.info("===> " + this.env.getProperty("spring.servlet.multipart.file-size-threshold"));
    }
}

Problem:

I can read the exact value this.env.getProperty("spring.servlet.multipart.file-size-threshold") on windows. But I couldn't read it on Linux. I'd like to know how I can access narcos configuration.

Additionally, file uploading doesn't work on Linux at all. Is there any specific configuration or permission setting?

Thanks in advance!

1 Answers

you can inject you config like:

@NacosValue(value = "${spring.application.name}", autoRefreshed = true)
private String applicationName;
Related