Java 环境env.getproperty不工作

Java 环境env.getproperty不工作,java,spring,eclipse,configuration,Java,Spring,Eclipse,Configuration,我对Environment env.getproperty有一个问题,env找不到本地属性,但它可以找到系统属性。我对这件事不太了解,我需要解决它。请帮帮我。 附上我的代码及其配置 Controllers.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/X

我对Environment env.getproperty有一个问题,env找不到本地属性,但它可以找到系统属性。我对这件事不太了解,我需要解决它。请帮帮我。 附上我的代码及其配置

Controllers.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd    
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-4.0.xsd">

<!-- Scans within the base package of the application for @Components to 
    configure as beans -->
<mvc:annotation-driven />
<context:component-scan base-package="com.mret.client.controller" />
<context:component-scan base-package="com.mret.client.security" />
<context:property-placeholder   location="classpath*:paremeters.properties" />  
控制器:

@Controller
public class OrdersController {
RestClient restClient = new RestClientImpl();
@Autowired
private Environment env;
String url = env.getProperty("url.services.search");
etc....}

  • 属性占位符不会将属性放置到环境中。它适用于操作系统级别上设置的变量

  • 更好地使用System.getProperty(“property_name”),它包括env、JVM属性,-D传递到java命令行的属性和yes-来自属性占位符的属性

  • >P>您也可以考虑使用您的URL作为Bean属性,而不是显式地使用它,而是通过Spring bean属性定义,如<代码> ${URL.Services 而不是在代码中使用属性名。经过一段时间后,可能很难找到加载了什么属性。这是更好的方法


    感动地回答。。。
    @Controller
    public class OrdersController {
    RestClient restClient = new RestClientImpl();
    @Autowired
    private Environment env;
    String url = env.getProperty("url.services.search");
    etc....}