【发布时间】:2016-02-08 13:13:19
【问题描述】:
我正在使用 SpringBoot MVC 模式开发一些 WebApplication。我有四个 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 就在这条路径上:
当我将我的静态文件夹从 REST 项目中的 CLIENT 项目重新定位到同一位置时,我的 WelcomeController 会看到 index.html 并且一切正常。
所以请有人帮我解决这个问题,我真的需要这个 html 在 CLIENT 项目中。我没有配置 xml 的经验,因为我在没有那些 xml 的 SpringBoot 课程上学到了。
我的 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);
}
}
提前致谢!
【问题讨论】:
-
这个类 ScoreTrackerApplication 在你的客户项目中吗?
-
不,她在 Rest 项目中
-
所以到目前为止,客户端还不是 Spring Boot 项目。只需在客户端创建一个类并使用 @SpringBootApplication 注释它
-
我这样做了,这解决了我的问题。 Tnx @BalajiKrishnan
标签: java maven spring-mvc spring-boot