في Spring.config، يمكنني تحديد كائن من نوع السلسلة؟

StackOverflow https://stackoverflow.com/questions/813452

  •  03-07-2019
  •  | 
  •  

سؤال

ويمكن أن أفعل شيئا من هذا القبيل:

  <object id="mydb" type="string">
    <value>"blah"</value> <-- note that <value> tag does not really exist
  </object>

وحتى أن أتمكن من استخدامها في وقت لاحق مثل ذلك:

  <object id="Someobject" type="Sometype">
    <property name="ConnectionString" ref="mydb"/>
  </object>

وتحرير: كان هذا الحل SpringFramework.NET كنت أبحث عنه. يبدو PropertyPlaceholderConfigurer موجود هناك أيضا. بفضل الجميع.

هل كانت مفيدة؟

المحلول

استخدم الربيع الذي بني في <لأ href = "http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html" يختلط = " نوفولو noreferrer "> PropertyPlaceholdConfigurer :

<bean id="PropertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
   <property name="location" value="classpath*:/application.properties"/>
</bean>

 <bean id="Someobject" class="somepackage.Sometype">
   <property name="connectionString" value="${mydb}"/>
 </bean>

وإعداد SYSTEM_PROPERTIES_MODE_OVERRIDE يسمح تجاوز الملكية عن طريق سطر الأوامر.

نصائح أخرى

استخدم النائبة على سبيل المثال على $ {السحر} وتحديد مفتاح / قيمة في ملف خصائص جنبا إلى جنب مع PostProcessor. Google لل<م> ربيع آخر معالج النائب ...

وأنا لا أرى أي ميزة لطريقك على الإطلاق. كل شيء التكوين لا يزال عادل.

والناس في بعض الأحيان تخريج سلاسل اتصال قاعدة البيانات إلى ملف .properties والحصول عليهم بهذه الطريقة. أعتقد أن أكثر منطقية من اقتراحكم.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top