Spring Boot 部署在Windows

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

相关推荐

  1. Spring Boot 部署Windows

    2024-03-11 00:56:08       25 阅读
  2. Docker上部署Springboot项目

    2024-03-11 00:56:08       43 阅读
  3. 云服务器上部署Springboot项目

    2024-03-11 00:56:08       49 阅读
  4. 如何服务器上部署springboot项目

    2024-03-11 00:56:08       42 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-11 00:56:08       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-11 00:56:08       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-11 00:56:08       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-11 00:56:08       20 阅读

热门阅读

  1. [three.js]UV动画

    2024-03-11 00:56:08       24 阅读
  2. 【IC设计】Scala、Chisel、Chiseltest版本兼容信息

    2024-03-11 00:56:08       20 阅读
  3. iOS面试题

    2024-03-11 00:56:08       26 阅读
  4. 力扣题库第3题:最长连续序列

    2024-03-11 00:56:08       18 阅读
  5. c++之迭代器与反向迭代器

    2024-03-11 00:56:08       27 阅读
  6. 序列的第 k 个数(c++题解)

    2024-03-11 00:56:08       23 阅读
  7. OceanBase社区版单节点安装搭建(Docker)

    2024-03-11 00:56:08       23 阅读
  8. Hyperf AOP 和 注解

    2024-03-11 00:56:08       23 阅读
  9. mysql 8 修改账号密码

    2024-03-11 00:56:08       18 阅读
  10. 链表简单功能的总结

    2024-03-11 00:56:08       23 阅读
  11. Ubuntu设置时区和时间同步

    2024-03-11 00:56:08       30 阅读
  12. 【国产MCU】-窗口看门狗(WWDG)

    2024-03-11 00:56:08       25 阅读