namespace, you need to import the context namespace: 3 Configure the external file in the configuration file, and the bean instance of C3P0, with the following code:XML version= "1.0" encoding= "UTF-8"?>Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"xsi:schemalocation= "Http://ww
1. Introduction of the context namespace in spring beans2. Original Bean configuration file3.vim test.properties Add properties file to src directorydriverclassname=org.gjt.mm.mysql.driverurl=jdbc:mysql://localhost:3306/spring?useunicode=true Characterencoding=utf-8username=rootpassword=11111111initialsize=1maxactive=5
Implements the Key-value in the spring Auto-injection properties file.1. In the Applicationcontext.xml configuration file, introduce the Xmlns:util= "Http://www.springframework.org/schema/util" xsi:schemalocation= " http// Www.springframework.org/schema/util http://www.springframework.org/schema/util/
To reference the properties or to configure in XML, there are two configuration methods for referencing a single properties file, and multiple properties files
One, read a single properties file
In the
• When configuring beans in a configuration file, it is sometimes necessary to mix the details of the system deployment in the bean's configuration (for example: file path, data source configuration information, etc.). And these deployment details actually need to be separated from the bean configuration
The Spring provides a propertyplaceholderconfigurer Beanfa
The 1.Spring provides a propertyplaceholderconfigurer Beanfactory post processor that allows the user to put part of the bean's configurationMove to the properties file. You can load a property in a propertyplaceholderconfigurer dependency file by using a variable of ${var} in the bean configuration file.General
-definitionsclasspath:Resources/Cls-web-resources-menuReloadableresourcebundlemessagesourceInternal use of Defaultresourceloader to load ResourceBundle, whileResourcebundlemessagesourcethe interior is directly using the Java.util.ResourceBundle. Getbundle (String baseName,locale locale, ClassLoader Loader) to obtain the i18n file information, and ResourceBundle is to use the "." As the basename delimiter (which is also our usual form),So there are
1.In the spring configuration file, configure the properties file that you want to readBeanclass= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> Propertyname= "Systempropertiesmodename"value= "System_properties_mode_override" /> Propertyname= "fileencoding"value= "UTF-8" />
In the project if some parameters often need to be modified, or later may need to be modified, then we'd better put these parameters in the properties file, the source code read properties inside the configuration, so that only need to change the properties of the file can b
To understand the spring-boot of this technique, you should know Spring-boot's core profile application.properties, and of course you can customize the profile **.properties information through annotations.
I. Reading the contents of the core profile information Application.properties
A core profile is a application.properties or application.yml configuration
/false.*/Public Boolean Getboolean (String Key) {String value = GetValue (key);if (value = = Null) {throw new Nosuchelementexception ();}return boolean.valueof (value);}/*** Remove the Boolean property, but the system property takes Precedence. returns the default value if it is null, or false if the content is not true/false.*/Public Boolean Getboolean (String key, boolean Defaultvalue) {String value = GetValue (key);return value! = null? Boolean.valueof (value): defaultvalue;}/*** Load multipl
Method one using Setter method Package Com.swift; Public class Book { private String bookname; Public void Setbook (String bookname) { this. BookName= bookname; } @Override public String toString () { return ' book [book= ' + bookname + "]"; }}In the spring framework, it is assumed that the object of the book class cannot be generated directly from the Servlet class, and that the property values of string bookname
As we all know, spring can read the values in properties in a @value way, You only need to configure Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in the configuration fileBeanID= "Propertyconfigurer"class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> Propertyname= "Location"> value>Classpath:config.propertiesvalue> Property>
At Spring boot learning 1 o'clock, you know that spring boot will read the configuration application.properties by default. So if we add a custom configuration item directly to the Application.properties, how to read it. Or do not want to put all the configuration in the application.properties, but instead of customizing a properties
The wildcard match in the Spring configuration file is comprehensive, but it is not possible to find the declaration of the element ' Context:property-placeholder ', which is basically the DTD parsing file that we did not introduce correctly when we introduced the namespace. Of course you have to import the appropriate package of
Spring's management of properties files is really easy.
Declare a class inside the app-config.xml.
class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
This class is used by spring to manage properties files.
The properties file is placed in t
In the spring framework, the Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer class can use the. Properties (Key/value form) In the fileSome dynamically set values (value), replaced in XML with a placeholder for the value of the key ($key $),The. properties file can customize some of the relevant
Let's start with the file structure of target directory.The properties file is stored in the Conf folder,The Lib folder contains a variety of jar files,Start.bat is the startup file for the Windows command line.What to do in the properties file1. Create a configuration
1. PrefaceThis article is mainly the collation of the two blog, thanks to the author's sharingSpring uses program mode to read the properties fileSeveral ways spring uses @value annotations to inject properties2. Configuration filesApplication.propertiessocket.time.out=10003. Load the configuration file directly with the spri
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.