春ブーツ - 組み込みのTomcatのない残りのコールクライアント

ディーパックSelvakumar:

私は春のブートの問題を把握しようとしていると私は新しいですと、私はここにいくつかの助けを得ることを考え春に。

私はデーモンとして実行され、リモートサーバにいくつかのGET要求を行い、スプリングブーツベースのJavaアプリケーションを持っています。(唯一のクライアントとして動作します)。

しかし、私の春のブートアプリケーションは、内部的に埋め込まれたTomcatコンテナを開始します。私の理解では、Javaアプリケーションがサーバとして動作している場合、それはTomcatを必要とするだろうということです。しかし、リモートマシンのGET APIを唯一の消費者であること、私のアプリケーションは、なぜそれが埋め込まれたTomcatを必要とするでしょうか?

私のPOMファイルでは、私は、それがさえGET呼び出しを行うために必要とされることを前提に、春・ブート・スターター・ウェブが指定されています。

しかし、組み込みTomcatを無効にするいくつかの研究を行った後、私は解決策を見つけました。

次の変更を行うには、

@SpringBootApplication(exclude = {EmbeddedServletContainerAutoConfiguration.class, 
WebMvcAutoConfiguration.class})

&application.ymlで

spring:
   main:
      web-environment: false

application.ymlの変更により、私のjarファイルがさえ始めるされていない、logbackログでも、ログは何もせずに、直接、中止します。

私はapplication.yml変更を削除する場合さて、私のジャー(のみ@SpringBootApplicationアノにおける最初の変化を伴う。)を開始したが、いくつかの例外になります。

 [main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

私の疑問はここでは、あります

1)それはスタンドアロンまたは埋め込まれ、Tomcatのです、本当にただのリモートマシンにGET APIの呼び出しを行うアプリケーションのために必要?

2)どのように私はこの例外を克服しないと安全に埋め込まれたTomcatを削除し、まだGET API呼び出しを実行しますか?

jwenting:

あなたは、Webアプリケーションのテンプレートから開始し、その後、Webアプリケーションの様相をオフにしようと、ここで完全に間違ったトラックにあるように見えます。

はるかに優れ、通常のコマンドラインクライアントテンプレートから開始し、で詳述するように、そこから行くことに関連した春のガイド

基本的にはアプリケーションがに減少し

@SpringBootApplication
public class Application {

private static final Logger log = LoggerFactory.getLogger(Application.class);

public static void main(String args[]) {
    SpringApplication.run(Application.class);
}

@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
    return builder.build();
}

@Bean
public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
    return args -> {
        Quote quote = restTemplate.getForObject(
                "http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
        log.info(quote.toString());
    };
}
}

そしてポンポンへ

    <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
    </dependency>
</dependencies>

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=168206&siteId=1