您并不需要所有这些注释才能使其正常工作。我建议您删除那些不是您故意添加的注释。
为了在与主上下文不同的路径上提供静态页面,这里是一种解决方法。
创建另一个简单的控制器类,如下所示。
import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;@Controllerpublic class Home { @RequestMapping(path = "/") public String getHome(){ return "redirect:/admin/ui/"; // make sure no space between colon (:) and endpoint name (/admin/ui) } @RequestMapping(path = "/admin/ui/" ) public String getAdminUi(){ return "/index.html"; // your index.html built by angular should be in resources/static folder // if it is in resources/static/dist/index.html, // change the return statement to "/dist/index.html" }}并且,请注意,我已经将该类标记为
@Controller不是,
@RestController因此如果您将其标记为
@RestController或尝试在任何现有的类中进行相同的标记,
@RestController您将很难轻松实现。因此,创建上面的另一个类没有害处。
这种方法的好处是,它不会破坏您现有的映射。上下文上下文路径也不会更改,因此无需理会其他端点路径。他们都应该像以前一样工作。
希望这有所帮助!



