Source Address: Https://github.com/roncoo/spring-boot-demoI. The order in which the configuration files are effective, the values are overwritten:1. @TestPropertySource annotations2. Command-line arguments3. Java System Properties (System.getproperties ())4. Operating system Environment variables5. Only the attributes contained in the random.* will produce a randomvaluepropertysource6. Application configura
1. Configuration files (*.properties) are often registered with the spring IOC in the following ways. JDBC Configuration - Context:property-placeholder Location= "Classpath:mybatis/db.properties"ignore-unresolvable= "true" /> Public number Information - Context:property-placeholder Location= "Classpath:wechat/official-account.properties"ignore-unresolvable= "true" /> Trigger Expression - C
The first thing to do is to build the spring MVC environment and then start the configuration in the properties file:First step: Inject the properties into the Springcontext, the specific path to adjust itselfBeanID= "config"class= "Org.springframework.beans.factory.config.PropertiesFactoryBean"> Propertyname= "Locations"> List> value>C
Background: The database information is generally configured in the Db.properties file, but the properties file parsing is a troublesome thing
The STRUTS2 Integrated Spring Framework provides a way to parse the properties file, in
Recently testing an old system, when the launch of the @value injected in the Chinese is garbled, the file use Gbk/utf-8 when the problem is garbled, but the spring configuration file inside the placeholder does not have this problem, the bean file set file-encoding="UTF-8"
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
We often put the properties file that spring needs to load under java/resources, so that the problem of storage causes the properties to be packaged in the root directory of the jar, so our spring configuration path is classpath*: Xxx.properties, but such a jar when we are r
Http://hi.baidu.com/alizv/blog/item/d8cb2af4094662dbf3d38539.html
In the real work, we often need to save some system configuration information, people generally choose the configuration file to complete, this article according to my work to read the properties configuration file a small summary, the main description is sprin
A new p.properties file is created under Project resource, which contains:Name=hahadaxiao Use:public static void Main (string[] args) { Classpathxmlapplicationcontext context = new Classpathxmlapplicationcontext ("A.xml"); Person p = Context.getbean ("P", person.class); System.out.println (p.name); }Print:HahadaxiaoIf there are multiple properties files, use the * wildcard charact
Beans : The root node of the XML file.xmlns : the abbreviation for XML namespace, because the tag name of the XML file is customized, and the tags that are written by yourself and others are likely to be named repeatedly, but the functions are different. So you need to add a namespace to differentiate this XML file from other XML files, similar to the package in Javaxmlns:xsi : XML
Because the XML file in spring is configured with the In this case, the result of the read failure occurs when the properties file is read by the normal program.For example:Properties prop =new Properties (); InputStream in = Object.Class.getresourceasstream ("/validateme
/XMLSchema-instance"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd ">IoC control inversion Spring injects complex type properties based on XML configuration file -BeanID= "Person"class= "Com.swift.person.Person"> Propertyname= "Name"value= "
Because the project needs to read the key-value pairs in the configuration file into the mapThe format is:001=123456789Add Configuration in Appcontext.xml:BeanID= "Loadkeyfromproperties"class= "Com.;landau.init.loadkeyformproperties"> Propertyname= "Keyfileresource"> value>Classpath:keys.propertiesvalue> Property> Bean>Java code: Public classLoadkeyformpropertiesImplementsInitializingbean {PrivateResource Keyfileresource;
Since spring's integration of Hibernate profile hibernate.cfg.xml is fairly good,
So, in my project, I've been using Spring's org.springframework.orm.hibernate.LocalSessionFactoryBean to replace the functionality of the Hibernate.cfg.xml file.
Localsessionfactorybean has several properties to look up hibernate mapping files: mappingresources, Mappinglocations, Mappingdirectorylocations and Mappingjarlocatio
There are three places for DAO, service, and servletGenerates an object by matching the file XML and injects properties of the object type, reducing the couplingDAO file Code: Package Com.swift; Public class Daouser { publicvoid Fun () { System.out.println ("I ' m Dao's Fun () ...................."); }}Service
SpringThe configuration of loading resource files is simplified and can be loaded by , this element is written as follows: If you want to configure multiple properties files This way is not allowed, will certainly out "Could not resolve placeholder". Solution:(1) in Spring 3.0 , you can write: (2) But in Spring 2.5 ,has no ignore-unresolvable attribute, So you
Spring gets the value method of propertiesConfiguring in Spring.xmlOddly enough, the Context-param loaded spring.xml cannot use ${xxx}Must be handed over to Dispatcherservlet management springmvc.xml to use?To give Springmvc dispatcherservlet to scan, instead of Spring listener Contextloaderlistener to scan, it can be more convenient to use "${xxx" to inject.1. Use $ to get
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.