我已经从我的" application.properties"中注入了一个值。文件。 test.scope的值配置为" testscope"。当我在我的程序中打印范围的值时,它打印为" defaultScope"。价值" testscope" (在application.properties中配置)为testScope变量打印,我没有设置任何默认值。
@RestController
@RequestMapping("testservice")
public class TestServiceController {
private static final Logger LOG = LoggerFactory.getLogger(TestServiceController.class);
@Value("${test.scope:defaultScope}")
private String serviceScope;
@Value("${test.scope}")
private String testScope;
@RequestMapping(value="/postTest", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<PostTestResponse> postTest( @RequestBody PostTestRequest request) {
LOG.info(" defaultScope gets printed = " + serviceScope);
LOG.info(" testscope gets printed = " + testScope);
return null;
}
}
我的假设是&#34; defaultScope&#34;只有在&#34; test.scope&#34;没有值的情况下才能打印在应用程序属性文件中设置。如果我遗失了什么,请告诉我。