2017-11-17 9 views
1

Environment env.getpropertyに問題があります。envはローカルプロパティを見つけられませんが、システムプロパティを検索します。私はこれについてあまり知らないし、私はそれを解決する必要があります。私を助けてください。 自分のコードとその設定を添付しました。環境env.getpropertyが動作しません

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

Paremeters.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

+0

移動しました... – Vadim

答えて

0
  1. property-placeholderは、プロパティをenvに配置しません。 OSレベルで設定される変数です。

  2. env、JVMプロパティ、javaコマンドラインに渡される-Dプロパティ、およびproperty-placeholderの-Dプロパティを含むSystem.getProperty( "property_name")。

  3. URLをBeanプロパティとして使用することも考えられますが、明示的に取得するのではなく、コード内にプロパティ名を持つ代わりに${url.services.search} のようなSpring Beanプロパティ定義を使用します。時間の経過後、どのプロパティがロードされたのかを見つけるのは難しいかもしれません。それは良いアプローチです...

関連する問題