首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将spring.config.location提供给WinSW以将SpringBoot安装为Windows服务?

如何将spring.config.location提供给WinSW以将SpringBoot安装为Windows服务?
EN

Stack Overflow用户
提问于 2020-09-21 22:00:43
回答 1查看 1.1K关注 0票数 0

我正在尝试设置一个WinSW来将Spring安装为Windows10上的一个Windows服务。到目前为止,当我只在XML文件中提供JAR文件名和配置选项时,它就可以工作了。

代码语言:javascript
复制
<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,服务将不会运行.

代码语言:javascript
复制
<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并不重要。它总是失败,日志只说:

代码语言:javascript
复制
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事件查看器显示此内容的一个错误:

代码语言:javascript
复制
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吗?

EN

回答 1

Stack Overflow用户

发布于 2021-02-16 21:44:23

我认为这应该是可行的:

代码语言:javascript
复制
<arguments>-Dspring.config.location=./application.yml -jar "myjar-1.0.0.jar"</arguments>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64000525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档