gpt4 book ai didi

java - WelcomeController 找不到index.html 的路径

转载 作者:行者123 更新时间:2023-11-30 07:36:54 27 4
gpt4 key购买 nike

我正在使用 SpringBoot MVC 模式开发一些 Web 应用程序。我有四个maven项目(DAO项目、REST项目(有用于启动应用程序的SpringBoot类)、SERVICE项目和CLIENT项目)。该项目通过依赖关系连接。

我的问题与 CLIENT 项目有关。我有 WelcomeController ,它看起来像这样:

package com.itengine.scoretracker.client.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class WelcomeController {

@RequestMapping("/")
public String welcome(){
return "static/html/index.html";
}
}

我的 html 位于此路径上:

enter image description here

当我将静态文件夹从 CLIENT 项目重新定位到 REST 项目中的同一位置时,我的 WelcomeController 会看到 index.html 并且一切正常。

所以请有人帮我解决这个问题,我真的需要这个 html 在 CLIENT 项目中。我没有配置 xml 的经验,因为我在 SpringBoot 类(class)中学习时没有使用这些 xml。

我的 web.xml 是空的,它们只有这个:

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application    2.3//EN" "java.sun.com/dtd/web-app_2_3.dtd"; > <web-app> <display-name>Archetype Created Web Application</display-name> </web-app>

我的主类是这样的:

package com.itengine.scoretracker.rest.init;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.boot.orm.jpa.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;


@ComponentScan("com.itengine")
@EntityScan("com.itengine")
@EnableJpaRepositories("com.itengine.scoretracker.dao.repository")
@SpringBootApplication
public class ScoreTrackerApplication
extends SpringBootServletInitializer{

@Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder builder){

return builder.sources(ScoreTrackerApplication.class);
}

public static void main(String[] args) {

SpringApplication.run(ScoreTrackerApplication.class, args);

}
}

提前致谢!

最佳答案

static文件夹移动到src/main/resources,以便它最终部署在类路径上。然后可以删除 / 的映射。

关于java - WelcomeController 找不到index.html 的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35270562/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com