Spring Boot 部署在Windows

13 篇文章 1 订阅

1、Spring Boot项目打成jar包。利用maven插件(多模块项目只需在服务模块添加插件)

   <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                    <skip>true</skip>
                    <encoding>UTF-8</encoding>
                    <compilerArguments>
                        <verbose/>
                        <bootclasspath>${java.home}/lib/rt.jar</bootclasspath>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lid/</classpathPrefix>
                            <mainClass>主启动类</mainClass>
                        </manifest>
                    </archive>
                    <!-- 排除配置文件 -->
                    <excludes>
                        <exclude>images/**</exclude>
                        <exclude>markdown/**</exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>

        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                    <include>**/*.yml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>

    </build>

2、简单启动脚本

@echo off
set JAVA_HOME=指定Java目录

set PATH=%JAVA_HOME%\bin;%PATH%

start javaw -Dfile.encoding=utf-8 -jar c:jar包位置 -Xms1024M -Xmx2048M -Xlog:disable -Xlog:exceptions=warning,safepoint=info,gc=trace,gc+heap=trace,logging=warning:file=/mnt/logs/gc.trace.log:uptime,level,tags,time,pid:filecount=5,filesize=10M -Duser.timezone=GMT+08 --spring.config.location=application.yml位置 -Djava.security.egd=file:/dev/./urandom 

1、javaw启动,后台运行无前台cmd窗口

2、--spring.config.location启动时指定配置文件,多个逗号隔开

3、-Dfile.encoding=utf-8Windows下项目保存数据到数据库中,中文乱码问题。排除请求乱码,接收乱码。可能和windows环境的默认编码(GBK)有关,需要启动时指定utf-8

4、Windows端口耗尽问题 TCP/IP 端口耗尽故障排除

  1. regedit 进入注册表 ,HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Tcpip/Parameters
  2. 新建:REG_DWORD(64),命名为MaxUserPort,设置值为60000,值类型为十进制,然后再新建一个命名为TCPTimedWaitDelay,设置值为30,值类型为十进制
  3. 管理员cmd下,netsh int ipv4 set dynamicport tcp start=2000 num=60000

3、停止端口脚本

@echo off
chcp 65001
color 0A
 
echo ===========Start to copy data===========
:start
cls
echo.请输入要关闭的端口号
set /p my_port=
echo.你输入的端口号是:%my_port%
echo 开始关闭执行脚本!!!!!!!!!!!!!!
 
@echo off&setlocal EnableDelayedExpansion 
set Port=
set Dstport=%my_port%
 
for /F "usebackq skip=4 tokens=2,5" %%a in (`"netstat -ano -p tcp"`) do (  
  for /F "tokens=2 delims=:" %%k in ("%%a") do (  
    set  Port=%%k  
  )  
  echo !Port! %%b >>portandpid.txt  
)  
for /F "tokens=2 delims=:" %%c in ("%1") do (  
    set  Port=%%c  
  )  
for /F "tokens=1,2 delims= " %%d in (portandpid.txt) do (  
    echo %%d   
    echo %Dstport%  
    if %%d == %Dstport% taskkill /f /pid %%e  
  )  
del portandpid.txt    
set Port=  
set Dstport=  
goto :eof  
 
echo '结束了'
 
 
pause
  • 12
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值