2020-09-28

记录一次项目

SpringBoot改war包

一、 打包

  1. pom文件 加 <packaging>war</packaging> (默认是jar,加入后为war)
  2. pom文件 加入:·
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <!--打包的时候可以不用包进去,别的设施会提供。事实上该依赖理论上可以参与编译,测试,运行等周期。
            相当于compile,但是打包阶段做了exclude操作-->
        <scope>provided</scope>
    </dependency>

    <!--最终打成war包,排除内置的tomcat-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

``

  1. 启动类 继承 SpringBootServletInitializer ,并且加上 @ServletComponentScan 注解
@SpringBootApplication
@ServletComponentScan
public class PjqtportalApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(PjqtportalApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(PjqtportalApplication.class);
    }

}

如图:在这里插入图片描述

二丶thymeleaf资源问题

  1. 部署到tomcat上资源路径404,需要改造成如下图

在这里插入图片描述

  1. ajax请求, 如下图,url 习惯有第一个 / ,部署到tomcat上会出现404,需要把url改成msg/addMsg
  $.ajax({
            url: '/msg/addMsg',
            type: 'post',
            // 设置的是请求参数
            data: $('#msgFrom').serialize(),
            // 用于设置响应体的类型 注意 跟 data 参数没关系!!!
            dataType: 'json',
            success: function (res) {
               
            },
            error:function (err) {
                $("input[name=vcode]").val("");
                layer.msg("[[#{p2}]]");
            }
        })

SpringBoot国际化:

1、 创建语言包资源
在这里插入图片描述

2、 创建语言文件,地区代码必须大写。
在这里插入图片描述

3、 配置文件配置语言资源路径包,不配置会找不到

spring.messages.basename=i18n.pjqt

在这里插入图片描述


window 后台部署jar bat文件

启动:

@echo off
START "pjqtmgmt" javaw -jar pjqt-1.0.jar
pause

关闭:根据应用端口关闭对应线程pid,修改port属性值即可

@echo off
chcp 65001
set port=8080
for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port%"') do (
    echo kill the process %%m who use the port %port%
    echo Closing, please wait %%m
    taskkill /f /pid %%m
)
Pause
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值