【问题标题】:Environment env.getproperty is not working环境 env.getproperty 不起作用
【发布时间】:2018-05-01 15:14:28
【问题描述】:

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" />  

参数.properties:

url.services.search=http://localhost:8080/mretcore/search
url.services.orderdetail=http://localhost:8080/mretcore/orderdetail?orderid=

控制器:

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

enter image description here

【问题讨论】:

  • 移到回答...

标签: java spring eclipse configuration


【解决方案1】:
  1. property-placeholder 不会将属性放入 env。它用于在操作系统级别设置的变量。

  2. 最好使用 System.getProperty("property_name"),它包括传递到 java 命令行的 env、JVM 属性、-D 属性,是的 - 来自属性占位符的那些。

  3. 1234563 而不是在代码中具有属性名称。一段时间后,可能很难找到加载了哪些属性。这是更好的方法...

【讨论】:

    猜你喜欢
    • 2014-07-16
    • 2014-01-17
    • 2021-11-13
    • 2020-11-25
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多