Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need to write "*" after classpath

Tags:

java

spring

xml

Why do we need to write "*" after classpath Here's an example

<import resource="classpath*:META-INF/spring/config.xml"/>
like image 562
Rostislav V Avatar asked Feb 09 '23 06:02

Rostislav V


2 Answers

That's a regex pattern (specially for spring) which means match rest of the location path.

Here in your case match all config.xml files in META-INF/spring folders of your classpath.

Here the Spring reference which exaplains it better in better way

4.7.2 Wildcards in application context constructor resource paths

The resource paths in application context constructor values may be a simple path (as shown above) which has a one-to-one mapping to a target Resource, or alternately may contain the special "classpath*:" prefix and/or internal Ant-style regular expressions (matched using Spring's PathMatcher utility). Both of the latter are effectively wildcards

like image 175
Suresh Atta Avatar answered Feb 14 '23 00:02

Suresh Atta


The classpath*: prefix means that, instead of just retrieving the first entry from the specified classpath location, all such entries will be used and merged together. Since each component (JAR) can contribute its own resource on the same classpath location, this makes it possible for each component to contribute its definitions into a common resource.

like image 39
Marko Topolnik Avatar answered Feb 13 '23 22:02

Marko Topolnik