Spring Profiles in Spring 3.1

Source: Internet
Author: User

Spring profiles is similar to MAVEN profiles, but spring profiles is a configuration file that is selected at the time of deployment, and MAVEN profiles chooses the active profile when it is packaged, and the other files are not included. The two approaches provide great convenience for deployment in different environments: for example, development environment, test environment, production environment, not always modify the configuration files, such as jdbc.properties, and sometimes forget, there is a big problem.

Now SRC (i.e. under the Classpath path) has: Jdbc_dev.properties/jdbc_test.properties/jdbc_production.properties three files, in the development environment, the test environment, Environment variables are configured in the production environment: Spring.profiles.active=dev, Spring.profiles.active=test, spring.profiles.active=production, they are one by one corresponding.

In spring's XML configuration file, you can load the JDBC properties file in the following way

<context:property-placeholder location= "Classpath:jdbc_${spring.profiles.active}.properties"/>


This is the recommended practice by setting environment variables. Another way is to configure it in Tomcat:

Add a property configuration to the%tomcat_home%/conf/catalina.properties file, such as the development environment is Spring.profiles.active=dev

Summary: This allows spring to read the corresponding configuration file in the appropriate environment by configuring it as above.




Spring Profiles in Spring 3.1

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.