spring boot 页面获取应用程序路径

1 定义拦截器:

public class PageContextInterceptor implements HandlerInterceptor{



@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
request.setAttribute("ctx", "http://"+request.getRemoteHost()+":"+request.getLocalPort()+"/spring-boot-fm");
return true;
}


@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {

}


@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
throws Exception {
}


}

2 拦截器加入applicationContext.xml


   

   
 


3 spring boot启动加载spring-xx.xml配置:
@ImportResource({ "classpath:spring-ctx.xml"})
@SpringBootApplication
public class SpringfreemarkerApplication {


4 页面使用:
  
 





拓展阅读
spring boot 启动sevlet配置

你可能感兴趣的:(Java)