我正在尝试以编程方式将Spring Boot应用程序上下文设置为root。上下文根的原因是我们希望从中访问该应用程序,localhost:port/{app_name}并将所有控制器路径附加到该应用程序。这是Web应用程序的应用程序配置文件。@Configurationpublic class ApplicationConfiguration { Logger logger = LoggerFactory.getLogger(ApplicationConfiguration.class); @Value("${mainstay.web.port:12378}") private String port; @Value("${mainstay.web.context:/mainstay}") private String context; private Set<ErrorPage> pageHandlers; @PostConstruct private void init(){ pageHandlers = new HashSet<ErrorPage>(); pageHandlers.add(new ErrorPage(HttpStatus.NOT_FOUND,"/notfound.html")); pageHandlers.add(new ErrorPage(HttpStatus.FORBIDDEN,"/forbidden.html")); } @Bean public EmbeddedServletContainerFactory servletContainer(){ TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory(); logger.info("Setting custom configuration for Mainstay:"); logger.info("Setting port to {}",port); logger.info("Setting context to {}",context); factory.setPort(Integer.valueOf(port)); factory.setContextPath(context); factory.setErrorPages(pageHandlers); return factory; } public String getPort() { return port; } public void setPort(String port) { this.port = port; }}这是主页的索引控制器。@Controllerpublic class IndexController { Logger logger = LoggerFactory.getLogger(IndexController.class); @RequestMapping("/") public String index(Model model){ logger.info("Setting index page title to Mainstay - Web"); model.addAttribute("title","Mainstay - Web"); return "index"; }}应用程序的新根目录应位于localhost:12378/mainstay,但仍位于localhost:12378。我错过了什么导致Spring Boot在请求映射之前不附加上下文根的问题?
添加回答
举报
0/150
提交
取消