码迷,mamicode.com
首页 > 编程语言 > 详细

spring 配置资源路径时候,classpath:/,classpath:,不带前缀的区别

时间:2014-12-02 22:43:35      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:spring   classpath   

/**
 * spring 配置资源路径时候,classpath:/,classpath:,不带前缀的区别,
 * 其实没区别,spring 规定 "classpath:" pseudo-URL,伪url路径,在处理这种路径前缀
 * 时候,会把这个伪url去掉。
 * @author doctor
 *
 * @time   2014年12月2日 下午6:28:12
 */
public class DefaultResourceLoaderPractice {
	@Test
	public void test_defaultResourceLoader()throws Throwable{
		DefaultResourceLoader defaultResourceLoader = new DefaultResourceLoader();
		Resource resource = defaultResourceLoader.getResource("springCorePractice/classPathResource.txt");
		
		System.out.println(resource.getFile());
	}
	
	@Test
	public void test_defaultResourceLoader_classpath()throws Throwable{
		DefaultResourceLoader defaultResourceLoader = new DefaultResourceLoader();
		Resource resource = defaultResourceLoader.getResource("classpath:springCorePractice/classPathResource.txt");
		
		System.out.println(resource.getFile());
	}
	@Test
	public void test_defaultResourceLoader_classpath_1()throws Throwable{
		DefaultResourceLoader defaultResourceLoader = new DefaultResourceLoader();
		Resource resource = defaultResourceLoader.getResource("classpath:/springCorePractice/classPathResource.txt");
		
		System.out.println(resource.getFile());
	}
}



/home/xxx/workspace-sts-3.6.0.RELEASE/doctor/springmvc-practice/target/test-classes/springCorePractice/classPathResource.txt
/home/xxx/workspace-sts-3.6.0.RELEASE/doctor/springmvc-practice/target/test-classes/springCorePractice/classPathResource.txt
/home/xxx/workspace-sts-3.6.0.RELEASE/doctor/springmvc-practice/target/test-classes/springCorePractice/classPathResource.txt


spring 配置资源路径时候,classpath:/,classpath:,不带前缀的区别

标签:spring   classpath   

原文地址:http://blog.csdn.net/doctor_who2004/article/details/41682049

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!