2016-12-20 10 views
0

私はスプリングブート時にプロパティファイルから値を取得しようとしています。 application.propertiesファイルはresourcesフォルダーとその内容の下にあります。スプリングブート@Valueが静的フィールドのために機能しない

TEST=someText 

コードは次のとおりです。

import org.springframework.beans.factory.annotation.Value; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.context.annotation.PropertySource; 

@SpringBootApplication 
@PropertySource("classpath:application.properties") 

public class Bb8Application { 


    @Value("${TEST}") 
    static String someString; 

    public static void main(String[] args) { 

     System.out.print(someString); 

    } 

} 

"someText"ではなく、結果としてNULLが返されます。私が紛失しているものがありますか?

答えて

1

スプリングでは静的フィールドに注入することはできません。本当に静的変数を使用したい場合は、これを試すことができますworkaround

関連する問題