springboot发布tomcat后静态文件路径问题

本文探讨了SpringBoot项目打成WAR包在Tomcat中部署时遇到的资源路径问题,包括如何修改application.properties和Thymeleaf模板引用静态资源的方法,以及在部署多个SpringBoot项目时的配置调整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.打成war发布tomcat是不是有资源路径问题?
修改application.properties文件 ; 添加: (sonicApplication,是对应war打包名)

server.servlet.context-path=/sonicApplication


2.如果用Thymeleaf 模板:修改html ,引用文件的方法,比如
<html lang="en" xmlns:th="http://www.thymeleaf.org">

 

<link rel="stylesheet" th:href="@{/css/assets/bootstrap.min.css}">
<script th:src="@{/js/assets/jquery.js}"></script>
<img th:src="@{/img/logo_full.jpg}"/>

<script th:inline="javascript">
    var ctx = [[@{/}]];
</script>

用ajax  ctx是获取war名
$http({
    method : "post",
    url : ctx + "appJson/getSearch",
    params : {"search": $scope.searchTest}
}).success(function (data) {
  
})

@ResponseBody
@RequestMapping("/getSearch")
public RestResultModule getSearch(
        @RequestParam(name = "search",required = false,defaultValue = "")String search){
    

如果Tomcat下部署多个springboot项目,要在 application.yml 添加 , 不然会报错
spring:
  # 多个springboot项目部署,需加
  jmx:
    enabled: false


springboot 发布外部tomcat : https://blog.youkuaiyun.com/weixin_38351566/article/details/83864259
不行留言.

 

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值