0

我试图按照此处的说明将我的 Spring Boot Web 服务作为 Windows 服务运行。如果我将 start 指向 org.springframework.boot.loader.JarLauncher,那么我的 Web 服务将启动并运行,但是当我尝试指向我添加的 Bootstrap 类时,我会收到“FindClass com/mycompany/Bootstrap failed”消息。所以 prunsrv 可以找到 SpringBoot 类,但找不到我的类。

有什么建议么?使用 org.springframework.boot.loader.JarLauncher 似乎可以正常启动 Windows 服务,但是我无法正常停止该服务,我必须在任务管理器中将其杀死。

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\GMC_TLG_DEV\Parameters\Java]
"Jvm"="E:\\Java\\jre1.8.0_121_32\\bin\\client\\jvm.dll"
"Classpath"="E:\\Apache\\prunsvc\\myspringbootjar.jar"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\GMC_TLG_DEV\Parameters\Start]
"Class"="org.springframework.boot.loader.JarLauncher"
"Mode"="jvm"
"Method"="main"



[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\GMC_TLG_DEV\Parameters\Start]
"Class"="com.mycompany.Bootstrap"
"Mode"="jvm"
"Method"="start"
4

2 回答 2

1

我能够弄清楚这一点,所以我发布了解决方案。

问题是 Spring Boot 不再将应用程序类存储在正常的类路径上。Spring boot 有自己的类加载器来加载应用程序类。为了将我的 com.mycompany.Bootstrap 类放在正确的位置,我将下面显示的 ANT 脚本添加到 Maven 构建中。该脚本来自某处的帖子,但我不记得在哪里。

听起来Radu的解决方案也很合适。

        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
            <execution>
                <phase>package</phase>
                <configuration>
                    <target>
                        <zip destfile="${project.build.directory}/${project.build.finalName}.jar"
                            update="true" compress="store">
                            <fileset dir="${project.build.directory}/classes" >
                                <include name="com/mycompany/Bootstrap.class"/>
                            </fileset>
                        </zip>
                    </target>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
于 2018-04-12T14:53:27.897 回答
0

我知道你的帖子已经很久了,但我今天遇到了同样的问题。这可能与自 1.4.0 以来 Spring Boot 中更改的 JAR 文件打包有关。

这里的说明适用于我的情况: https ://github.com/spring-projects/spring-boot/issues/6792#issuecomment-243564648

于 2018-04-11T19:39:16.943 回答