Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using classpath: in spring

People also ask

How does classpath work in Spring?

By default Spring Boot will serve static content from a directory called /static (or /public or /resources or /META-INF/resources) in the classpath.

What is classpath scanning in Spring boot?

A Classpath scanning basically means, detecting the classes that need to be managed by the Spring under a specified package. You need to make use of the spring @ComponentScan annotation with the @Configuration for classpath scanning.

How do I give path to ClassPathResource?

Map<String, Object> env = new HashMap<>(); try (FileSystem fs = FileSystems. newFileSystem(uri, env)) { Path path = fs. getPath("/path/myResource"); try (Stream<String> lines = Files. lines(path)) { .... } }


Does classpath: search for resource relative to the document in which it is specified(in case of web applications)?

No, classpath: is always relative to the classpath root. If you put a / at the start of the path, it is silently removed.

Is it more fast to search if i give direct location of resource instead e.g. classpath:/WEB-INF/classes/myfolder/myfile.txt

No, that won't work at all. The classpath root contains /WEB-INF/classes, so the path should be relative to that.

Don't confuse classpath: paths with file paths, they have no relation to each other.


Take a look at http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/resources.html#resources-classpath-wildcards

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.

So classpath: starts at the root of your classpath.