In java projects, xml files are generally used to store some configuration information
General programming, most of them are used to store configuration information. Take JDBC as an example, you can Write the database connection string to xml. If you want to modify the data source, you only need to change the xml. There is no need to recompile the java file. Moreover, these configuration information are put together, and other people can It is much more convenient when reading the code you wrote. In addition to configuration information, you can also write some corresponding relationships in xml in
framework, which is actually a kind of configuration information. Take struts as an example, The xml configuration is the relationship between the page URL and the background java class (action). When configuring and modifying, you only need to change an xml file. There is no need to search for the java code one by one
After the java project is completed, each module should be independent, and the relationship between modules can be maintained using xml. Spring is such a framework
A good project needs to be well scalable If all logical relationships and configuration information are written into the code, the scalability of the program will be poor. In order to solve this problem, xml can schedule the entire project (spring)
There is also the use of xml as data storage, but it is rarely used. Most of it is used to store configuration information
Different xmls play different roles: for example, configuration files## in web projects #Plays the role of configuring paths and redirecting requests. The hibernate configuration file plays the role of configuring the connection database and related attributes and mapping the entity class and the relational database . The spring configuration file plays the role of Configure the instantiation of javabeans and the role of the integration framework. There are also some xml files that store some data for the program to read. In fact, in the final analysis, the configuration file is equivalent to a small database for storing data. Using dom4j and other jar packages that read and write configuration files can read the configuration files, and it can also be used as a cross-language medium! !
The above is the detailed content of Detailed introduction to the role of XML in JAVA projects. For more information, please follow other related articles on the PHP Chinese website!