记录一次项目
SpringBoot改war包
一、 打包
- pom文件 加
<packaging>war</packaging> (默认是jar,加入后为war)
- 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>
``
- 启动类 继承
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资源问题
- 部署到tomcat上资源路径404,需要改造成如下图
- 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