我正在尝试设置一个WinSW,以便在Windows10上安装Spring Boot JAR作为Windows服务。到目前为止,当我在XML文件中提供JAR文件名和配置选项时,它就可以工作了。
<service>
<id>testSB/id>
<name>testSB</name>
<description>This service runs a spring boot JAR as service.</description>
<executable>java</executable>
<startmode>Automatic</startmode>
<delayedAutoStart>true</delayedAutoStart>
<onfailure action="restart" delay="10 sec"/>
<onfailure action="restart" delay="20 sec"/>
<onfailure action="none"/>
<resetfailure>1 hour</resetfailure>
<arguments>-jar "myjar-1.0.0.jar" </arguments>
<log mode="roll-by-size-time">
<sizeThreshold>20480</sizeThreshold>
<pattern>yyyyMMdd</pattern>
<autoRollAtTime>00:30:00</autoRollAtTime>
<zipOlderThanNumDays>5</zipOlderThanNumDays>
</log>
<logpath>%BASE%/logs</logpath>
</service>
它工作了,我可以看到主页。
但是,若我添加--spring.config.location=application.yml,服务将不会运行。
<service>
<id>testSB/id>
<name>testSB</name>
<description>This service runs a spring boot JAR as service.</description>
<executable>java</executable>
<startmode>Automatic</startmode>
<delayedAutoStart>true</delayedAutoStart>
<onfailure action="restart" delay="10 sec"/>
<onfailure action="restart" delay="20 sec"/>
<onfailure action="none"/>
<resetfailure>1 hour</resetfailure>
<arguments>-jar "myjar-1.0.0.jar" --spring.config.location=./application.yml</arguments>
<log mode="roll-by-size-time">
<sizeThreshold>20480</sizeThreshold>
<pattern>yyyyMMdd</pattern>
<autoRollAtTime>00:30:00</autoRollAtTime>
<zipOlderThanNumDays>5</zipOlderThanNumDays>
</log>
<logpath>%BASE%/logs</logpath>
</service>
使用相对路径也没关系
./application.yml
,使用%BASE%:
%BASE%/application.yml
,绝对路径:
C:\path\to\app.yml
。它总是失败,日志只显示:
2020-09-21 16:57:25,626 DEBUG - Completed. Exit code is 0
2020-09-21 16:57:30,560 DEBUG - Starting WinSW in console mode
2020-09-21 16:57:30,930 DEBUG - User requested the status of the process with id 'testSB'
2020-09-21 16:57:30,932 DEBUG - Completed. Exit code is 0
2020-09-21 16:57:35,363 DEBUG - Starting WinSW in service mode
2020-09-21 16:57:35,380 INFO - Starting java -jar "myjar-1.0.0.jar" --spring.config.location=C:\path\to\application.yml
2020-09-21 16:57:35,395 DEBUG - Completed. Exit code is 0
Windows事件查看器显示此内容的错误:
Service cannot be started. System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at WinSW.Util.ProcessHelper.StartProcessAndCallbackForExit(Process processToStart, String executable, String arguments, Dictionary`2 envVars, String workingDirectory, Nullable`1 priority, ProcessCompletionCallback callback, Boolean redirectStdin, LogHandler logHandler, Boolean hideWindow)
at WinSW.WrapperService.StartProcess(Process processToStart, String arguments, String executable, LogHandler logHandler, Boolean redirectStdin)
at WinSW.WrapperService.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)
有没有办法提供这个春季启动选项来启动JAR??