A方式
B方式比A方式少个[color=red][b]*[/b][/color]
两个配置只有一个字符之差,项目启动时使用B方式就启动不了,报service未加载
实际使用B方式,在spring里为精确匹配,不能匹配通配符,A方式才可以配匹通配符。
原文
[url=http://docs.spring.io/spring/docs/2.5.x/reference/resources.html]传送门[/url]
[quote]
4.7.2.2. The classpath*: prefix
When constructing an XML-based application context, a location string may use the special classpath*: prefix:
ApplicationContext ctx =
new ClassPathXmlApplicationContext("classpath*:conf/appContext.xml");
This special prefix specifies that all classpath resources that match the given name must be obtained (internally, this essentially happens via a ClassLoader.getResources(...) call), and then merged to form the final application context definition.
[Note] Classpath*: portability
The wildcard classpath relies on the getResources() method of the underlying classloader. As most application servers nowadays supply their own classloader implementation, the behavior might differ especially when dealing with jar files. A simple test to check if classpath* works is to use the classloader to load a file from within a jar on the classpath: getClass().getClassLoader().getResources("<someFileInsideTheJar>"). Try this test with files that have the same name but are placed inside two different locations. In case an inappropriate result is returned, check the application server documentation for settings that might affect the classloader behavior.
The "classpath*:" prefix can also be combined with a PathMatcher pattern in the rest of the location path, for example "classpath*:META-INF/*-beans.xml". In this case, the resolution strategy is fairly simple: a ClassLoader.getResources() call is used on the last non-wildcard path segment to get all the matching resources in the class loader hierarchy, and then off each resource the same PathMatcher resoltion strategy described above is used for the wildcard subpath.
[/quote]
<import resource="classpath*:config/**/spring*.xml" />
B方式比A方式少个[color=red][b]*[/b][/color]
<import resource="classpath:config/**/spring*.xml" />
两个配置只有一个字符之差,项目启动时使用B方式就启动不了,报service未加载
实际使用B方式,在spring里为精确匹配,不能匹配通配符,A方式才可以配匹通配符。
原文
[url=http://docs.spring.io/spring/docs/2.5.x/reference/resources.html]传送门[/url]
[quote]
4.7.2.2. The classpath*: prefix
When constructing an XML-based application context, a location string may use the special classpath*: prefix:
ApplicationContext ctx =
new ClassPathXmlApplicationContext("classpath*:conf/appContext.xml");
This special prefix specifies that all classpath resources that match the given name must be obtained (internally, this essentially happens via a ClassLoader.getResources(...) call), and then merged to form the final application context definition.
[Note] Classpath*: portability
The wildcard classpath relies on the getResources() method of the underlying classloader. As most application servers nowadays supply their own classloader implementation, the behavior might differ especially when dealing with jar files. A simple test to check if classpath* works is to use the classloader to load a file from within a jar on the classpath: getClass().getClassLoader().getResources("<someFileInsideTheJar>"). Try this test with files that have the same name but are placed inside two different locations. In case an inappropriate result is returned, check the application server documentation for settings that might affect the classloader behavior.
The "classpath*:" prefix can also be combined with a PathMatcher pattern in the rest of the location path, for example "classpath*:META-INF/*-beans.xml". In this case, the resolution strategy is fairly simple: a ClassLoader.getResources() call is used on the last non-wildcard path segment to get all the matching resources in the class loader hierarchy, and then off each resource the same PathMatcher resoltion strategy described above is used for the wildcard subpath.
[/quote]