【发布时间】:2019-07-15 15:11:16
【问题描述】:
我需要帮助,我的 Spring Boot 2 服务器从第一个 Web 生成其他网站(带有 html、css ext ext 的文件夹),但是这些网站/html 无法访问,Spring 给我错误 404,未找到。
我将在 .jar 中使用 Maven 构建项目
项目的名称是这样的:
---
|_folder (Directory with webapps generated, NOT DELIVERED)
. |_webapp1
. |_webapp2
|_src
. |_main
. . |_java
. . |_resources
. . . |_public (With first web)
. . . |_static (Template used to generate other web site, i simply copy this directoy in other directory, doing templateServices.copyDirectory("target/classes/static/", "folder/webapp1");
---
我尝试了这种配置,但不起作用。
@Configuration
@EnableWebMvc
public class StaticResourceConfiguration implements WebMvcConfigurer {
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/", "classpath:/public/", FileController.uploadingDir};
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
}
}
【问题讨论】:
-
你能显示一些代码吗?
-
关于什么?非常感谢您的支持
-
啊,你没有代码。至少正确解释你想要做什么?您有一个 Spring Boot 应用程序,它在
public目录中生成一个静态网站,然后您希望能够从创建这些网站的同一个应用程序交付该网站? -
Spring Boot 2 的 jar 必须交付用户生成其他网站的第一个网站。 jar 生成“文件夹”,所有这些网站在 public static final String uploadingDir = System.getProperty("user.dir");
-
我没有代码交付生成的网站,Spring boot的配置是默认的,我尝试了addResourceHandlers,但没有,tomcat嵌入不交付这些新的webapp。我把这段代码贴出来。
标签: java spring spring-boot web directory