


Detailed introduction to Spring's code examples for using multiple xml configuration files
Spring uses multiple xml configuration files, friends in need can refer to them.
1, Define the contextConfigLocation parameter in web.xml. Spring will use this parameter to load all comma-delimited xml. Without this parameter, spring loads the web-inf/applicationContext.xml file by default.
<context-param><param-name>contextConfigLocation</param-name> <param-value>classpath*:conf/spring/applicationContext_core*.xml, classpath*:conf/spring/applicationContext_dict*.xml,classpath*:conf/spring/applicationContext_hibernate.xml, classpath*:conf/spring/applicationContext_staff*.xml,classpath*:conf/spring/applicationContext_security.xml classpath*:conf/spring/applicationContext_modules*.xmlclasspath*:conf/spring/applicationContext_cti*.xml classpath*:conf/spring/applicationContext_apm*.xml</param-value> </context-param>
The contextConfigLocation parameter defines the Spring configuration file to be loaded. The principle is explained as follows:
1. Use ServletContextListener to implement.
Spring provides an implementation class of ServletContextListener, ContextLoaderListener, which can be used
as a listener. It will automatically find the applicationContext.xrnl file under WEB-INF/ when it is created. Therefore, if there is only one configuration file and the file name is applicationContext.xml, you only need to add the following code to the web.xml
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>If there are multiple configuration files that need to be loaded, consider using the
Therefore, the parameter name should be contextConfigLocation when configuring context-param.
The web.xml file with multiple configuration files is as follows:
<1-- XML 文件的文件头二〉<?xml version="l.O" encoding="工80-8859-1"?> < 1-- web.xm1 文件的DTD 等信息一〉<!DOCTYPE web-app PUBLIC "-//Sun Microsystems. 工口c.//DTD Web Application 2.3//EN"''http://java.sun.com/dtd/web-app_2_3.dtd''> <web-app><!一确定多个配置文件> <context-param><1-- 参数名为contextConfigLocation…〉 <param-name>contextConfigLocation</param-name><!一多个配置文件之间以,隔开二〉 <param-value>/WEB-工NF/daoContext.xml./WEB-INF/applicationContext.xml</param-value> </context-param><!-- 采用listener创建Applicat工onContext 实例--> <listener><listener-class>org.spr工ngframework.web.context.ContextLoader Listener</listener-class></listener></web-app>If there is no contextConfigLocation specified configuration file, Spring will automatically find the application
Context.xrnl configuration file. If there is contextConfigLocation, use the configuration file determined by this parameter.
configuration files. Commas ",", spaces "" and semicolons ";" can all be used as characters string delimiter.
Load the configuration file or fail to create the ApplicationContext instance normally
Use load-on-startup Servlet accomplish.
automatically search for the applicationContext.xml file under WEB-IN.
Load-on-startup The value of Servleto load-on-startup is smaller, which is more appropriate, because it is necessary to ensure that Application
web.xml file:
<servlet> <servlet-name>context</servlet-name><servlet-class>org.springframework.web.context.ContextLoaderServlet</ servlet-class><load-on-startup>l</load-on-startup> </servlet>
. The web and nl files with multiple configuration files are as follows:
<!-- XML 文件的文件头--><?xml version="1.0" encoding="工SO-8859-1"?> <! -- web.xml 文件的DTD 等信息→<!DOCTYPE web-appPUBLIC "-//Sun Microsystems , 工口c.//DTD Web Application 2.3//EN" ''http://java.sun.com/dtd/web-app_2_3.dtd''><web-app> <'一确定多个配置文件一><context-param> <!-- 参数名为contextConfigLocation--><param-name>contextConfigLocation</param-name><!-- 多个配置文件之间以,隔开一〉 <param-value>/WEB-工NF/daoContext.xml, !WEB-工NF/applicationContext.xml</param-value> </context-param><!一采用load-on-startup Servlet 创建Applicat工onContext 实例一〉 <servlet><servlet-narne>context</servlet-narne> <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class> <!一下面值小一点比较合适,会优先加载一〉<load-on-startup>l</load-on-startup></servlet> </web-app>
2, use the matching character
<context-param><param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext*.xml</param-value></context-param>
. For example, if Hibernate is used, put the hibernate related configuration in applicationContext- hibernate.xml is a file, and some global related information is placed in applicationContext.xml. Other configurations are similar. In this way, it can be loaded without writing separated by spaces or commas!
3, if you use struts to load multiple spring configuration files. The following configuration is actually the contextConfigLocation variable.struts-config.xml add this
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"><set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml,/WEB-INF/action-servlet.xml,,,,,,,"/>4, if it is non-j2ee Apply direct program loading.
ApplicationContext act = new ClassPathXmlApplicationContext(new String[]{"bean1.xml","bean2.xml"});BeanDefinitionRegistry reg = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(reg); reader.loadBeanDefinitions(new ClassPathResource("bean1.xml")); reader.loadBeanDefinitions(new ClassPathResource("bean2.xml")); BeanFactory bf = (BeanFactory)reg;
Finally, explain the difference between the following classpath*: and classpath:
classpath*: appears to load the same file from multiple jar files.classpath: Only the first file found can be loaded.
The above is the detailed content of Detailed introduction to Spring's code examples for using multiple xml configuration files. For more information, please follow other related articles on the PHP Chinese website!

Well-formedXMLiscrucialfordataexchangebecauseitensurescorrectparsingandunderstandingacrosssystems.1)Startwithadeclarationlike.2)Ensureeveryopeningtaghasaclosingtagandelementsareproperlynested.3)Useattributescorrectly,enclosingvaluesinquotesandavoidin

XMLisstillusedduetoitsstructurednature,humanreadability,andwidespreadadoptioninenterpriseenvironments.1)Itfacilitatesdataexchangeinsectorslikefinance(SWIFT)andhealthcare(HL7).2)Itshuman-readableformataidsinmanualdatainspectionandediting.3)XMLisusedin

The structure of an RSS document includes three main elements: 1.: root element, defining the RSS version; 2.: Containing channel information, such as title, link, and description; 3.: Representing specific content entries, including title, link, description, etc.

RSS documents are a simple subscription mechanism to publish content updates through XML files. 1. The RSS document structure consists of and elements and contains multiple elements. 2. Use RSS readers to subscribe to the channel and extract information by parsing XML. 3. Advanced usage includes filtering and sorting using the feedparser library. 4. Common errors include XML parsing and encoding issues. XML format and encoding need to be verified during debugging. 5. Performance optimization suggestions include cache RSS documents and asynchronous parsing.

RSS and XML are still important in the modern web. 1.RSS is used to publish and distribute content, and users can subscribe and get updates through the RSS reader. 2. XML is a markup language and supports data storage and exchange, and RSS files are based on XML.

RSS enables multimedia content embedding, conditional subscription, and performance and security optimization. 1) Embed multimedia content such as audio and video through tags. 2) Use XML namespace to implement conditional subscriptions, allowing subscribers to filter content based on specific conditions. 3) Optimize the performance and security of RSSFeed through CDATA section and XMLSchema to ensure stability and compliance with standards.

RSS is an XML-based format used to publish frequently updated data. As a web developer, understanding RSS can improve content aggregation and automation update capabilities. By learning RSS structure, parsing and generation methods, you will be able to handle RSSfeeds confidently and optimize your web development skills.

RSS chose XML instead of JSON because: 1) XML's structure and verification capabilities are better than JSON, which is suitable for the needs of RSS complex data structures; 2) XML was supported extensively at that time; 3) Early versions of RSS were based on XML and have become a standard.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor
