我正在尝试设置一个WinSW来将Spring安装为Windows10上的一个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>它可以工作,我可以看到主页面。
但是,如果我添加-.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%/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 0Windows事件查看器显示此内容的一个错误:
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吗?
发布于 2021-02-16 21:44:23
我认为这应该是可行的:
<arguments>-Dspring.config.location=./application.yml -jar "myjar-1.0.0.jar"</arguments>https://stackoverflow.com/questions/64000525
复制相似问题