SPINGMVC External Properties File read (Java Recycle properties content)

Source: Internet
Author: User

Now that you have the properties path for Applicationcontext.xml, Java no longer has to set the properties path.

Applicationcontext.xml

Before change:

<!--Properties--

<context:property-placeholder location= "File:/sb/env.properties"/>

After the change:

<!--Properties--
<bean class= "Jp.co.softbank.faqapi.common.conf.AppConfig" >
<property name= "Locations" >
<list>
<value>file:/sb/env.properties</value>
</list>
</property>
</bean>

Java files:

Import java.util.Properties;

Import org.springframework.beans.BeansException;
Import Org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
Import Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
Import org.springframework.stereotype.Component;

/**
*コンフィギュレーション.
*/
@Component
public class AppConfig extends Propertyplaceholderconfigurer {

private properties Properties;

@Override
protected void Processproperties (Configurablelistablebeanfactory beanfactorytoprocess, properties properties) throws beansexception {
Super.processproperties (beanfactorytoprocess, properties);
This.properties = properties;
}

/**
* Envのプロパティ obtained
* @param keyキー
* @return
*/
public string Getenvproperty (string key) {
return Properties.getproperty (key);
}

}

SPINGMVC External Properties File read (Java Recycle properties content)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.