当前位置:   article > 正文

Spring Boot 部署在Windows

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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61

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
  • 2
  • 3
  • 4
  • 5
  • 6

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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/218548
推荐阅读
相关标签
  

闽ICP备14008679号