为什么jaca类中的@Value无法加载application.properties java springboot中的



亲爱的大师,请帮帮我为什么我的@Value无法加载我的application.properties,我需要添加任何配置吗?这是我的代码我的DataprocClient.java

@Component
public class DataprocClient {
@Value("${ipdataprocessing}")
private String ipDataProcessing;
public ResponseModel reqDataproc(String uri,MultiValueMap<String, String> post) {
System.out.println("ipDataProcessing"+ipDataProcessing);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(post, headers);
RestTemplate restTemplate = new RestTemplate();
ResponseModel responseModel = new ResponseModel();
responseModel = restTemplate.postForObject(ipDataProcessing, request, ResponseModel.class);
return responseModel;
}
}

我的应用程序属性

dataprocurl=http://10.245.4.132:8100/api/kswpService
ipdataprocessing=http://127.0.0.1:8080
server.port=80
server.max-http-header-size=10000000
spring.boot.admin.url=http://localhost:8888
management.security.enabled=false
spring.application.name=DataProcess-DB

我是新来的,请帮帮我……

@Value注释仅在您的类通过Spring的依赖注入机制实例化时有效,例如,如果它用@Component(或@Controller或其他几个(进行注释,然后用@Autowired在其他地方注入。

在您的情况下,该类不是@Component,我假设您手动实例化它(使用new DataprocClient()(,因此在bean实例化期间不会填充用@Value注释的字段。

相关内容

最新更新