我有一個現有的應用程序,它是一個用Java編寫的用maven管理的碼頭應用程序。有幾個基本任務可以從瀏覽器運行,但主要是從命令行(或Jenkins)運行時一次運行所有任務。啓動Spring Boot並使用maven配置文件撥打電話
它通過調用特定的Maven輪廓做到這一點
所以maven的命令行調用
mvn clean install -P autorun
自動運行配置文件是
<profile>
<id>autorun</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>install</phase>
<configuration>
<target>
<property name="runtime_classpath" refid="maven.runtime.classpath"/>
<java classname="com.app.tool.Client" >
<arg value="-h" />
<classpath>
<pathelement path="${runtime_classpath}"/>
</classpath>
</java>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
沒有在客戶端的主流程
public static void main(String... args) throws Exception { ...
基本上
- 創建一個
org.eclipse.jetty.server.Server
對象 - 使用war文件揭開序幕http服務器應用
採用了多項
org.springframework.http.client.ClientHttpRequest
對象使用代碼沿着線斷火多項任務的ClientHttpRequest request = restTemplate .getRequestFactory() .createRequest( new URI("http://localhost:8080/tool/spring/" + jobName), HttpMethod.GET); ClientHttpResponse clientHttpResponse = request.execute(); if (clientHttpResponse.getStatusCode().value() != HttpStatus.OK_200) { throw new RuntimeException(...); }
我現在要重構應用程序以各種理由。我的目標是保持當前的設計,儘管目前的主要用途更多的是控制檯應用程序,但我想添加一些更有用的交互功能。因此,爲了最終切入點,我開始將應用程序重新編寫爲Spring Boot應用程序。我想仍然能夠從命令行(和詹金斯)中解僱我想要的工作。有沒有一個簡單的(&等效)方式來做到這一點與Spring Boot & Maven?我使用的主要如此可能斷火的應用程序,我需要一個開關傳遞到這裏
public static void main(String[] args) throws Exception {
SpringApplication.run(SpringBootStartUpConfig.class, args);
}
我猜,很多目前用於啓動服務器的代碼可以被傾倒,但我掙扎找到實現這一目標的最佳方式? (我更喜歡使用Maven,因爲這是我們正在使用的核心工具,但如果這是更好的事情,我可以使用Gradle)。
從命令行啓動它爲什麼會發出請求不一樣?當使用maven時,你可以使用'mvn springBoot:run'來啓動應用程序,而不是配置文件或其他任何東西。 –