Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么来自maven依赖项的静态内容在spring boot中提供?_Java_Maven_Spring Boot - Fatal编程技术网

Java 为什么来自maven依赖项的静态内容在spring boot中提供?

Java 为什么来自maven依赖项的静态内容在spring boot中提供?,java,maven,spring-boot,Java,Maven,Spring Boot,我有一个简单的多模块maven项目。第一个模块是角度前端,第二个模块是spring boot应用程序 我将前端maven模块配置为构建angular应用程序,并将组装好的文件收集到frontend.jar。因此,我有以下存档结构: jar -tf frontend.jar | sort --------------------------- META-INF/ META-INF/MANIFEST.MF META-INF/maven/ META-INF/maven/sample-project/

我有一个简单的多模块maven项目。第一个模块是角度前端,第二个模块是spring boot应用程序

我将前端maven模块配置为构建angular应用程序,并将组装好的文件收集到
frontend.jar
。因此,我有以下存档结构:

jar -tf frontend.jar | sort
---------------------------
META-INF/
META-INF/MANIFEST.MF
META-INF/maven/
META-INF/maven/sample-project/
META-INF/maven/sample-project/frontend/
META-INF/maven/sample-project/frontend/pom.properties
META-INF/maven/sample-project/frontend/pom.xml
static/
static/3rdpartylicenses.txt
static/assets/
static/assets/img/
static/assets/img/loading.gif
static/favicon.png
static/index.html
static/main.8e44da4898d2a7a95ed3.js
static/polyfills.d72edd4c76dc8f27444a.js
static/runtime.a66f828dca56eeb90e02.js
static/styles.0afb74a990d73ad0b544.css
之后,我添加到spring boot
.pom
文件对前端模块的依赖性,并构建整个项目

<dependency>
    <groupId>sample-project</groupId>
    <artifactId>frontend</artifactId>
    <version>${version}</version>
</dependency>

样本项目
前端
${version}
最后,在启动SpringBootWeb应用程序之后,我发现,当我转到
localhost:port/
url时,我得到了我的应用程序

接下来的问题是:spring boot如何理解它应该从
frontend
依赖项提供静态内容?请注意,我在spring引导模块资源中没有静态文件夹。

在Java中,“JAR”只是组织应用程序进行部署的一种方式。您不能根据类或资源在磁盘上的实际JAR或位置来寻址它们(除非您正在编写自己的
类加载器
)。这些物理详细信息在运行时不可用。从运行时的角度来看,一切都是扁平的,有点像docker层

所以,真的没有“哪个类来自哪个依赖项”的概念。这有时会导致一些细微的错误,但这也是jarjar、OSGi和新的Java9模块等技术存在的原因

通常,SpringBoot服务于/static下类路径中可用的所有内容。没有关于资源来自“哪个jar”或“哪个目录”的概念