Java Spring引导返回404,用于docker的静态资源
我和docker一起使用spring boot。我在SpringBoot项目中有静态资源,当我使用MVNSpring:boot-run运行它时,一切正常,资源可用。但当我使用命令从中创建docker图像时 来自openjdk的Java Spring引导返回404,用于docker的静态资源,java,angular,docker,spring-boot,Java,Angular,Docker,Spring Boot,我和docker一起使用spring boot。我在SpringBoot项目中有静态资源,当我使用MVNSpring:boot-run运行它时,一切正常,资源可用。但当我使用命令从中创建docker图像时 来自openjdk的:8-jdk-alpine 添加/target/example-*.jar/ 曝光8080 入口点java-jar示例-*.jar 那么我的静态资源不可由localhost:8080使用。应用程序已成功启动(日志中没有错误)。jar文件中的资源可能很棘手 以下是一些解决问
:8-jdk-alpine
添加/target/example-*.jar/
曝光8080
入口点java-jar示例-*.jar
那么我的静态资源不可由localhost:8080使用。应用程序已成功启动(日志中没有错误)。jar文件中的资源可能很棘手 以下是一些解决问题的技巧:
- Resources=>src/main/Resources/META-INF/Resources/static
- 查看模板=>src/main/resources/WEB-INF/Templates
最棘手的一点是,如果我只是在没有docker的情况下运行这个jar,一切都会正常运行。但你是对的-解决问题的主要方法是将所有资源放在src/main/resources/static文件夹下。我对docker和resources也有类似的问题,但资源是上载的,所以不能存储在
src/main/resources/static
文件夹,如果你们有线索的话,提前谢谢
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/static/**").addResourceLocations("classpath:META-INF/resources/static/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:META-INF/resources/webjars/");
registry.addResourceHandler("/**").addResourceLocations("classpath:META-INF/");
}
buildscript {
ext {
springBootVersion = '2.0.0.M7'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
maven { url 'http://repo.spring.io/plugins-release' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'io.spring.gradle:propdeps-plugin:0.0.9.RELEASE'
classpath 'org.springframework:springloaded:1.2.6.RELEASE'
}
}
ext {
springBootVersion = '2.0.0.M7'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'groovy'
//apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'propdeps'
apply plugin: 'propdeps-idea'
group = 'com.example.app'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
configurations {
includeInJar
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-groovy-templates')
compile('org.codehaus.groovy:groovy')
includeInJar("org.webjars:bootstrap:4.0.0")
includeInJar("org.webjars:jquery:3.3.1")
configurations.compile.extendsFrom(configurations.includeInJar)
}
idea {
module {
inheritOutputDirs = true
}
}
jar {
from configurations.includeInJar.collect { it.isDirectory() ? it : zipTree(it) }
}
compileJava.dependsOn(processResources)