2016-04-27 4 views
3

を使用するときに、なぜ春ブーツが二回SpringApplicationRunListenerを実行しない私には、以下の方法の簡単なSpringApplicationRunListener実装定義された:ユーレカ

2016-04-27 10:37:37.702 INFO 5720 --- [   main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http) 
2016-04-27 10:37:37.703 INFO 5720 --- [   main] b.a.test.LazyFilterRuntimeListener  : It's finished 
:私はどんな春の雲依存せずに実行すると、私は以下のログを取得する

@Override 
public void finished(ConfigurableApplicationContext configurableApplicationContext, Throwable throwable) { 
    logger.info("It's finished"); 
} 

ただし、次の依存関係を追加すると:

<dependency> 
    <groupId>org.springframework.cloud</groupId> 
    <artifactId>spring-cloud-starter-eureka</artifactId> 
</dependency> 

は、その後のラインがさえ春の起動ロゴの前に、開始時に一度終了(春クラウド/ユーレカなしなど)でかつ1回、2回記録され、「それは終わっています」と表示されます:それはまたラインを言及

2016-04-27 10:37:35.500 INFO 5720 --- [   main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring[email protected]255b53dc: startup date [Wed Apr 27 10:37:35 CEST 2016]; root of context hierarchy 
2016-04-27 10:37:35.638 INFO 5720 --- [   main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 
2016-04-27 10:37:35.785 INFO 5720 --- [   main] trationDelegate$BeanPostProcessorChecker : Bean 'encrypt.CONFIGURATION_PROPERTIES' of type [class org.springframework.cloud.bootstrap.encrypt.KeyProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 
2016-04-27 10:37:35.786 INFO 5720 --- [   main] trationDelegate$BeanPostProcessorChecker : Bean 'encryptionBootstrapConfiguration' of type [class org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfiguration$$EnhancerBySpringCGLIB$$268d5fc8] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 
2016-04-27 10:37:35.839 INFO 5720 --- [   main] b.c.test.LazyFilterRuntimeListener  : It's finished 
2016-04-27 10:37:35.842 INFO 5720 --- [   main] be.company.test.TestApplication : Started TestApplication in 0.499 seconds (JVM running for 0.86) 

    . ____   _   __ _ _ 
/\\/___'_ __ _ _(_)_ __ __ _ \ \ \ \ 
(()\___ | '_ | '_| | '_ \/ _` | \ \ \ \ 
\\/ ___)| |_)| | | | | || (_| | )))) 
    ' |____| .__|_| |_|_| |_\__, |//// 
=========|_|==============|___/=/_/_/_/ 
:: Spring Boot ::  (v1.2.7.RELEASE) 


... 

2016-04-27 10:37:37.702 INFO 5720 --- [   main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http) 
2016-04-27 10:37:37.703 INFO 5720 --- [   main] b.c.test.LazyFilterRuntimeListener  : It's finished 
2016-04-27 10:37:37.703 INFO 5720 --- [   main] be.company.test.TestApplication : Started TestApplication in 2.423 seconds (JVM running for 2.721) 

「...でアプリケーションを開始しました」が2回表示されます。

この現象が発生する特別な理由はありますか?私はSpringApplicationRunListener特定の豆に依存して作成しようとしています。しかし、春のクラウドを追加すると、最初にfinished()メソッドに達したときにコンテキストが作成されていないため、現在はエラーが発生しています。

+0

。問題を報告しましたか?もしそうなら、あなたはそれへのリンクを投稿できますか? – Ruben

+0

いいえ、報告しませんでした。私たちはこの事件について、私たちの事件について取り組んだ。 Beanにはコンテキストが存在する必要があるため、Beanが最初に存在するかどうかを確認しました。 https://github.com/camunda/camunda-bpm-spring-boot-starter/commit/19a6061533d56499896025a2886ca48514344a9a#diff-c41da622737469f43899d92d98d1edb0R40。この問題が1.2.xか1.3.xのいずれかに結びついているかどうかはわかりません。 – g00glen00b

答えて

2

実際には、ロギングのためのダブルコールの問題があります。デフォルトでは、Spring BootはINFOレベルのロギングを設定します。

Previous version of spring boot before 1.3、あなたが1.2.7を使用しているとして、それは

を使用して、追加したあなたのMDC 値を持つスプリングブーツのCONSOLE_LOG_PATTERNを上書きすることができない場合、あなたがすべてのログメッセージ が書き込まれて生きているようです二度! (一度春のブートコンソールアペンダと とMDCを使用して、コンソールアペンダがパターンに追加され、一度に)春ブーツの新しいバージョンで

しかし、春ブーツで1.3 あなただけで簡単に春ブーツからbase.xmlを含むことができ、 logback.xmlを作成します。

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <include resource="org/springframework/boot/logging/logback/base.xml" /> 

    <root level="INFO"> 
     <appender-ref ref="FILE" /> 
    </root> 
</configuration> 

詳細については、あなたが従うことができます:How to disable logback ConsoleAppender in Spring Boot

リソースリンク:私は同じ問題を経験してい

  1. https://github.com/spring-projects/spring-boot/issues/1788
  2. https://github.com/spring-projects/spring-boot/issues/2558
+1

私はこれが何を意味するのかよく分かりません。ログ自体が2回繰り返されることをお勧めしますか?しかしこれは問題ではありません。メソッドは確実に2回呼び出されます。タイムスタンプも違っていて、 "Started TestApplication Started in XX"の "XX"も異なっているので、これはまったくログの問題ではないかと疑います。 ** ** Springのクラウド+ Springブートにのみ適用されます。私はSpringブート(1.2.7)を単独で実行しても問題はありません。 – g00glen00b

+0

合意、同じ問題をここでは、春の雲の設定を使用して起こっている – Ruben

+2

問題は、春の雲のコモンズのパッケージに依存しています。これはすでにhttps://github.com/spring-cloud/spring-cloud-commons/pull/100で修正されており、バージョン1.1.0以上で利用可能です。 – Ruben

関連する問題