java - Use properties file in Spring -
i newbie spring framework. in spring application there details below details needs maintain in properties file.
transaction name transaction id txt_cco = 70001 txt_cci = 70002 txt_ssm = 20005 in controller, there action below.
@requestmapping(value = {"/validatewalletamount**"}, method = requestmethod.get) public @responsebody string validatewalletamount(@requestparam("mobile") string mobile, @requestparam("pin") string merchant_pin, @requestparam("provider") string provider, @requestparam("currency_type") string currency_type, @requestparam("amount") string amount) { //to - txntypeid provider return "02 | 1000.00 | 0.00"; } according request parameter provider need relevant transaction type id. example, if provider txt_cco transaction type id should 70001.
can please me achieve this
i have 2 options
- load properties using
<util:properties /> - use
@propertysource,environmentabstraction.
using <util:properties />
to load properties file can use propertiesfactorybean or easier <util:properties /> tag (which uses propertiesfactorybean underneath easier configure). see here more information.
simply add following xml configuration
<util:properties id="transactions" location="classpath:transaction.properties" /> now have properties bean named transactions can inject controller after can use obtain property need.
@autowired private properties transactions; using @propertysource , environment abstraction
another solution add @configuration class @propertysource load properties. after can use environment obtain properties. see environment section in reference guide more information.
@configuration @propertysource("classpath:transaction.properties") public class myconfiguration {} in controller can use environment obtain properties.
@autowired private environment env; resource support
of course spring property support usable resource loading approach of spring. file: , http: prefixes work well, default loading rules applying used applicationcontext.
Comments
Post a Comment