Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between classpath and classpath*: in web.xml

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you what is the difference between classpath and classpath*: in web.xml, I believe most people do not know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it together.

What's the difference between classpath: and classpath*: in web.xml?

Classpath: will only look for files in your class path

Classpath*: contains not only the class path, but also the jar file (class path) for search.

Sometimes multiple profiles are configured in a fuzzy matching way.

But if the configuration file is in the jar package, the fuzzy match will not be found. You can configure multiple profiles separated by commas.

Such as:

Org.springframework.web.context.ContextLoaderListener contextConfigLocation classpath*:applicationContext.xml, classpath*:app-datasource.xml, classpath*:app-memcached.xml, classpath*:app-ibatis.xml, classpath*:app-rest.xml

Storage location:

Under 1:src

You need to define it in web.xml as follows:

ContextConfigLocation classpath:applicationContext.xml

Under 2:WEB-INF

You need to define it in web.xml as follows:

ContextConfigLocation WEB-INF/applicationContext*.xml

How web.xml configures spring through contextConfigLocation

SSI Framework profile path problem:

1 + N paths of struts2: src+src (configurable) name: struts.xml + N

1 path to spring: src name: applicationContext.xml

1 + N paths of ibatis: src+src (configurable) name: SqlMapConfig.xml + N

After deployment to tomcat, the configuration file in the src directory will automatically copy to the classes directory of the application, just like the class file.

When the configuration file of spring starts, it loads the applicationContext.xml in the web-info directory.

The runtime uses applicationContext.xml under the web-info/classes directory.

Configure web.xml to make the two paths consistent:

ContextConfigLocation / WEB-INF/classes/applicationContext.xml

Loading of multiple configuration files

ContextConfigLocation 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*.xml classpath*:conf/spring/applicationContext_cti*.xml classpath*:conf/spring/applicationContext_apm*.xml

The contextConfigLocation parameter defines the Spring configuration file to load.

First of all, the configuration file related to Spring must start with "applicationContext-" and conform to the idea that convention is better than configuration, which is much better in terms of efficiency and error rate.

It is also best to put all the Spring configuration files in a unified directory, if the project is large, you can also build a directory under this directory. So the program doesn't look messy.

The configuration in web.xml is as follows:

Xml code

< param-name>

ContextConfigLocation

< param-value>

Classpath*:**/applicationContext-*.xml

< /context-param>

"* * /" indicates any directory

"* * / applicationContext-*.xml" represents a XML file that starts with "applicationContext-" in any directory.

You can modify it according to your needs. It is best to put all Spring configuration files in a unified directory, such as:

ContextConfigLocation classpath:/spring/applicationContext-*.xml

Then load the information defined by Bean from the XML file in the Web system:

ServletContext servletContext = request.getSession (). GetServletContext (); ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext (servletContext); above is all the content of the article "classpath in web.xml: what's the difference between classpath and classpath*:". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report